获取路线外的当前路径 [英] get current path outside of Route
本文介绍了获取路线外的当前路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此URL中:http://siteName/html/test
我当然想在路线内赶上test
.
效果很好:
I want to catch test
, of course inside the route.
This works great:
Route::get('test', function()
{
return Route::getCurrentRoute()->getPath();
});
但是我想像这样在我的route.php
文件中访问任何路由之外的路径:
But I want to access the path outside of any route and in my route.php
file like this:
// routes.php
return Route::getCurrentRoute()->getPath();
Route::get('test', function()
{
...
});
推荐答案
以防您尝试捕获所有路线.将此添加为您的最后一条路线.
In case you try to catch all routes. Add this as your last route.
Route::any('{all}', function($uri)
{
return Route::getCurrentRoute()->getPath();
})->where('all', '.*');
这篇关于获取路线外的当前路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文