如何禁用ReactJ的Laravel路由 [英] How can I disable laravel routes for ReactJs
问题描述
我在Laravel上的应用程序中遇到了路由问题,因为我在laravel资源目录中使用ReactJs路由.使用laravel 5.3和最新的React Js.
I've issue with routes in my application on Laravel as i am using ReactJs routes inside laravel resource directory. Using laravel 5.3 and latest React Js.
resources/assets/js/src/Route.js
resources/assets/js/src/Route.js
const routes = (
<Route path='/' component={DefaultPageLayout}>
<IndexRoute component={App} />
<Route path="register" component={MasterPageLayout}>
<IndexRoute component={Register} />
</Route>
</Route>
)
export default routes;
routes/web.php
routes/web.php
Route::get('/', function () {
return view('welcome');
});
当我尝试重定向到注册页面时,它返回以下错误
When I'm trying redirect to Register Page, It returns below error
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 755
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
at require_once('/opt/lampp/htdocs/react_laravel/public/index.php') in server.php line 21
如何解决Laravel中的路线问题?我想有来自react而不是Laravel的路线.我应该进行哪些更改,以便从一开始,Laravel路由就将每个请求移交给React路由
How can I resolve routes issue in Laravel? I want to have routes from react and not Laravel. What changes should i make so that from the beginning the Laravel routes handover each request to React routes
推荐答案
您只需将以下代码添加到
You just need to add below code to
// change your existing app route to this:
// we are basically just giving it an optional parameter of "anything"
Route::get('/{path?}', function($path = null){
return View::make('app');
})->where('path', '.*');
//regex to match anything (dots, slashes, letters, numbers, etc)
您的路线将对laravel中的任何前端JavaScript框架都适用.
Your routes will be work fine any front-end JavaScript framework inside laravel.
这篇关于如何禁用ReactJ的Laravel路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!