You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel+React(Inertia)项目无法渲染组件求助

解决Inertia无法渲染React组件的问题

核心修复:控制器返回响应

你的AppController中index方法没有返回Inertia生成的响应,这是页面空白的直接原因。修改代码如下:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Inertia\Inertia;

class AppController extends Controller
{
   public function index() {
     // 必须返回Inertia响应
     return Inertia::render("Index");
   }
}

检查文件路径拼写

你标注的Index.jsx路径写成了resouces/js/Pages/Index.jsx,正确路径应为resources/js/Pages/Index.jsx(注意多了字母c),若实际文件路径与代码引用不一致,会导致组件无法被加载。

其他排查项

  • 确保Vite开发服务正在运行:执行npm run dev启动资源编译服务
  • 检查依赖完整性:确认已安装@inertiajs/react、react、react-dom,缺失则执行npm install @inertiajs/react react react-dom
  • 查看页面源代码:检查@inertia指令是否渲染出包含组件数据的<div>,若为空说明服务端响应异常
  • 清除Laravel缓存:执行php artisan optimize:clear避免缓存导致的路由/配置问题

内容的提问来源于stack exchange,提问作者Dev Yego

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 02:33:18