【发布时间】:2015-08-11 09:56:11
【问题描述】:
我遇到了一个问题,当我去一个带有 href 的路线时,例如
example.com/user/foo
然后单击带有 href 的链接,例如
example.com/cart/bar
URL 设置为
example.com/user/cart/bar
我得到一个错误。问题是 URL 没有重置为根目录,而是将子目录('user')保留在 URL 中。
这是一个用户路径的链接示例:
<li><a href="/user/{{ Auth::user()->username }}">{{ Auth::user()->firstName }} {{ Auth::user()->lastName }}</a></li>
还有路线:
Route::get('/user/{username}', array(
'before' => 'auth',
'as' => '/user/{username}',
'uses' => 'ProfileController@user'
));
对视图的调用结果:
return View::make('profile.user')
->with('user', $user);
此时,网址为:
example.com/user/john_smith
但是,假设我想查看我的购物车,它的 href 为:
<li><a href="store/cart">Cart</a></li>
还有路线:
Route::get('store/cart', array(
'as' => 'get-cart',
'uses' => 'StoreController@getCart'
));
对视图的调用结果:
return View::make('store.cart')->with('products', Cart::contents());
网址应该是:
example.com/store/cart
其实是
example.com/user/store/cart
我得到一个“NotFoundHttpException”
【问题讨论】: