Laravel:捕获所有没有/api/段的路由 [英] Laravel: Catch all routes that does not have /api/ segment

查看:124
本文介绍了Laravel:捕获所有没有/api/段的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要捕获所有路由,但其中包含/api/段的路由除外. 我知道如何捕捉每条路线

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@serveFrontend')->where('all', '(.*)');

但是我需要更改什么,以便此字符串不捕获我的api路由?

But what do I need to change so that my api routes aren't captured by this string ?

推荐答案

您可以捕获路径不是以api

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.

这篇关于Laravel:捕获所有没有/api/段的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆