如何重定向到 Laravel 中的基本路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22660947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to redirect to a base route in Laravel
提问by Nikunj Kumar
I have an issue in laravel routing ,
我在 Laravel 路由中遇到问题,
I am able to go to the following routes independently:
我可以独立前往以下路线:
*localhost/jmeercat/public/home*
*localhost/jmeercat/public/manageProject/newlycreatedproject*
But if I am on the route *localhost/jmeercat/public/manageProject/newlycreatedproject*
and click on home page link I am redirected to localhost/jmeercat/public/manageProject/homepath instead of localhost/jmeercat/public/home.
但是,如果我在路线上*localhost/jmeercat/public/manageProject/newlycreatedproject*
并单击主页链接,我将被重定向到localhost/jmeercat/public/manageProject/home路径而不是localhost/jmeercat/public/home。
I am using return Redirect::to('home')
method.
我正在使用return Redirect::to('home')
方法。
回答by ajtrichards
Check the Laravel documentation on Named Routes - http://laravel.com/docs/routing#named-routes
检查有关命名路由的 Laravel 文档 - http://laravel.com/docs/routing#named-routes
Named routes make referring to routes when generating redirects or URLs more convenient. You may specify a name for a route like so:
命名路由使得在生成重定向或 URL 时更方便地引用路由。您可以为路由指定一个名称,如下所示:
Route::get('/home', array('as' => 'home', 'uses' => 'HomeController@home'));
You may use the route's name when generating URLs or redirects:
您可以在生成 URL 或重定向时使用路由名称:
$url = URL::route('home');
$redirect = Redirect::route('home');