Search code examples
phplaravellaravel-routing

API Routes handles by web Route in Laravel


I'm building SPA (Single-page-application) by Laravel and React JS.

I have some API routes in api.php of Laravel.

And I defined this route in web.php of Laravel to handle web routes by React JS.

Route::view('{any}', 'app')->where('any', '.*');

But the problem is that API routes are handled by the above code.

What should I to do ?

I don't want to write routes in Laravel and rewrite them in React JS twice.


Solution

  • Use these routes

    Route::view('/{any?}', 'app')->where('any', '^(?!api\/)[\/\w\.-]*');
    

    This will exclude api routes