NotFoundHttpException 命名路由 PHP Laravel 5.2

NotFoundHttpException named route PHP Laravel 5.2

Route::get('user/profile', function () {
return 'test' })->name('profile');

但是我调用 address/profile 时总是出错 如果我使用 address/user/profile 它工作得很好。

我的浏览器中显示的错误列表:

NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

我错过了什么? 提前致谢。

您需要将路线从 user/profile 更改为 profile

Route::get('profile', function () {
   return 'test' })->name('profile');

name() 只为路由创建别名而不改变 URL

Route::get('user/profile', function () {
return 'test'; })->name('profile');

试试This.Hope会成功的!!