How to disable larvel routes for ReactJs

I have a problem with routes in my Laravel application, as I use ReactJs routes in the laravel resources directory. Using laravel 5.3 and latest React 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

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

When I try to redirect to the Register page, it returns below the 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

How can I solve the route problem in Laravel? I want routes to react, not Laravel. What changes should I make so that from the very beginning Laravel routes transmit every request for React routes

+4
source share
1 answer

You just need to add the code below

// 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)

JavaScript laravel.

+6

Source: https://habr.com/ru/post/1663705/


All Articles