首页 > 解决方案 > Laravel Blade 404 中的 React Router Not Found Error 以获得更深的 url 级别

问题描述

我正在将 React 整合到现有的Laravel 应用程序中。

虽然 document.blade 的 url 正在工作,并且我的 react 组件正在其中呈现,但当我尝试使用 React Router 创建子链接时,我收到 404 错误,未找到。

关于为什么 React Rooter 不起作用的任何想法?

在我的 web.php 中,我尝试了以下所有方法:

Route::get('{locale}/documents', function() {
        return view('documents');
    });

Route::get('{locale}/documents', function() {
        return view('documents');
    })->where('{locale}/documents', '.*');

Route::view('{locale}/{path?}', 'documents');

在我的 app.js 中,我尝试过:

return (

    <Switch>
        <Route exact path="/" component={Index} />
        <Route path="/create" component={AddDocument} />
        <Route path="/edit" component={EditDocument} />
        <Route path="/details" component={DocumentDetails} />
    </Switch>
);

或者

return (
    <Switch>
        <Route exact path="/" component={Index} />
        <Route path={props.locale + "document/create"} component={AddDocument} />
        <Route path={props.locale + "document/edit/:id"} component={EditDocument} />
        <Route path={props.locale + "document/details/:id"} component={DocumentDetails} />
    </Switch>
);

我正在访问顶级 url: http://localhost:8090/public/en/documents(呈现我的应用程序组件),但下面的任何内容都不能像这样工作: http://localhost:8090/public/en /documents/create(不显示我的 Create 组件或其他任何内容。我收到 404 错误)

有没有人做过类似的事情?先感谢您。

标签: reactjslaravel

解决方案


推荐阅读