我目前正在构建一个 CMS 系统,我为其创建了一组路由,该组以“cms”为前缀。问题出在我的 menu.blade 文件中,我在其中使用超链接 HREF 属性中的前缀调用了路由并得到了以下错误。
路线 [cms/welcome] 未定义。(查看:C:\Bitnami\wampstack-7.1.27-0\apache2\htdocs\nathanreynolds\resources\views\layouts\CMS\menu.blade.php)
我可以通过在浏览器顶部输入 url 来访问路由就好了。但是当使用{{route('cms/welcome')}}调用路由时,它会返回此错误。
menu.blade.php
<ul id="CMSnav">
<li><a href="{{route('cms/welcome')}}">Welcome</a></li>
<li><a href="{{route('cms/about')}}">About</a></li>
<li><a href="{{route('cms/contact')}}">Contact us</a></li>
</ul>
web.php(路由)
/** CMS routes **/
Route::group(['prefix'=>'cms','middleware'=>'auth'],function(){
Route::get('welcome','cmsController@index');
Route::put('updateLayouts','cmsController@updateLayouts');
Route::get('about','cmsController@about');
Route::get('contact','cmsController@contact');
//Route::resource('/CMS','cmsController');
});
通过php artisan route:list打印路线列表
C:\Bitnami\wampstack-7.1.27-0\apache2\htdocs\nathanreynolds>php artisan route:list
+--------+---------------+-------------------------------------------+-----------------------------------+---------------------------------------------------------------------------+------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+---------------+-------------------------------------------+-----------------------------------+---------------------------------------------------------------------------+------------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | Blogs | Blogs | App\Http\Controllers\pagescontroller@Blogs | web,Closure |
| | GET|HEAD | CMS/about | | App\Http\Controllers\cmsController@about | web,auth,Closure |
| | GET|HEAD | CMS/contact | | App\Http\Controllers\cmsController@contact | web,auth,Closure |
| | PUT | CMS/updateLayouts | | App\Http\Controllers\cmsController@updateLayouts | web,auth,Closure |
| | GET|HEAD | CMS/welcome | | App\Http\Controllers\cmsController@index