如何禁用ReactJs的laravel路由

时间:2016-12-14 06:01:12

标签: reactjs laravel-5 url-routing

我在Laravel的应用程序中遇到路由问题,因为我在laravel资源目录中使用ReactJs路由。使用laravel 5.3和最新的React Js。

资源/资产/ 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;

路由/ web.php

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

当我尝试重定向到注册页面时,它返回错误

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中的路线问题?我希望有反应而不是Laravel的路线。我应该做些什么改变,以便从一开始Laravel路由将每个请求移交给React路线

1 个答案:

答案 0 :(得分:7)

您只需将以下代码添加到

即可
// 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框架中正常工作。