reactjs - Laravel Blade 404 中的 React Router Not Found Error 以获得更深的 url 级别
问题描述
我正在将 React 整合到现有的Laravel 应用程序中。
- 我创建了一个单独的视图(documents.blade.php),在其中呈现了我的根 React 组件。
- 在我的 web.php 中,我创建了一个指向此文档视图的路由。
- 在我的 React 组件中,我使用的是 React Router。
虽然 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 错误)
有没有人做过类似的事情?先感谢您。
解决方案
推荐阅读
- python - 使用 lxml etree iterparse 解析大于 3gb 的 Xml 文件
- regex - 注册前协助
- amazon-rds - 如何查看极光无服务器的慢查询日志
- java - 运行时添加 PropertySourcesPlaceholderConfigurer bean
- javascript - 单击时将焦点切换到隐藏的文本框
- c - 为什么会导致 SIGSEGV(信号 11)(核心转储)?
- web-deployment - ServletContext 初始化超时
- parsing - 哪个解析器组合器适用于 Data.Text 并包含在 vanilla GHC 中?
- android - 当我只修改少量代码行时,APK 变得太大
- f# - 如何对滑块的值更改事件做出反应?