Url Laravel 4-路由未重置为根
我遇到了一个问题,当我使用href访问路线时,例如 example.com/user/foo 然后单击带有href的链接,如 example.com/cart/bar URL设置为 example.com/user/cart/bar 我得到一个错误。问题是URL没有重置为根目录,而是将子目录(“用户”)保留在URL中 以下是指向用户路由的链接示例:Url Laravel 4-路由未重置为根,url,laravel,routes,Url,Laravel,Routes,我遇到了一个问题,当我使用href访问路线时,例如 example.com/user/foo 然后单击带有href的链接,如 example.com/cart/bar URL设置为 example.com/user/cart/bar 我得到一个错误。问题是URL没有重置为根目录,而是将子目录(“用户”)保留在URL中 以下是指向用户路由的链接示例: <li><a href="/user/{{ Auth::user()->username }}">{{ Auth::u
<li><a href="/user/{{ Auth::user()->username }}">{{ Auth::user()->firstName }} {{ Auth::user()->lastName }}</a></li>
对视图的结果调用:
return View::make('profile.user')
->with('user', $user);
return View::make('store.cart')->with('products', Cart::contents());
此时,URL为:
example.com/user/john_smith
但是,假设我想查看我的购物车,它的href为:
<li><a href="store/cart">Cart</a></li>
对视图的结果调用:
return View::make('profile.user')
->with('user', $user);
return View::make('store.cart')->with('products', Cart::contents());
URL应为:
example.com/store/cart
但事实是
example.com/user/store/cart
我得到一个“NotFoundHttpException”您可以使用url()
helper函数来生成一个绝对url,例如:
<li><a href="{{ url('store/cart') }}">Cart</a></li>