Laravel: Catch all routes that does not have /api/ segment

后端 未结 2 1869
遇见更好的自我
遇见更好的自我 2021-02-19 21:35

I need to catch all routes, except those that have /api/ segment in them. I know how to catch every single route

Route::any(\'{all}\', \'AngularController@serveF         


        
相关标签:
2条回答
  • 2021-02-19 22:07

    Just place route(s) with /api/ segment before this one and it will work as you want. All API related URLs will be processes by first route, everything else will be processed with second one.

    0 讨论(0)
  • 2021-02-19 22:19

    You can catch all routes where the path does not start with api

    Route::any('{all}', 'AngularController@serveFrontend')->where('all', '^(?!api).*$');
    

    Or simply leave your catchall as the last route and it'll work as expected.

    0 讨论(0)
提交回复
热议问题