简体   繁体   中英

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.

Use these routes

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

This will exclude api routes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM