【问题标题】:Laravel page not found error while using global route prefix使用全局路由前缀时未找到 Laravel 页面错误
【发布时间】:2019-01-17 20:20:58
【问题描述】:

我想用 laravel 建立多语言网站,我想让 urls seo 友好。

所以我使用RouteServiceProvider为整个路由添加了语言前缀

Route::group([
            'middleware' => 'web',
            'namespace' => $this->namespace,
            'prefix' => $this->app->getLocale()
        ], function ($router) {...);

我们应该为语言提供任何参数吗?因为我没有为路由使用任何参数..

Route::group(["prefix"=>trans("routes.admin")],function (){
    Route::get("/",["as"=>"admin.index","uses"=>"AdminController@index"]);
});

我在 stackoverflow、laravel.com 上研究过它,但找不到任何有用的东西。

我该如何解决这个错误?任何帮助将不胜感激。

【问题讨论】:

    标签: php laravel routes


    【解决方案1】:

    $this->app->getLocale() 返回字符串,试试这个:

    Route::group([
            'middleware' => 'web',
            'namespace' => $this->namespace,
            'prefix' => '{locale?}'
        ], function ($router) {
                 $router->get("admin",["as"=>"admin.index","uses"=>"AdminController@index"]);
            });
    

    【讨论】:

    • 只是一个普通的404错误。另外我查看了laravel.log,没有关于这个的日志。
    • app.test/en/admin
    • 老兄,这是 RouteServiceProdiver 类
    • Route::get("admin",["as"=>"admin.index","uses"=>"AdminController@index"]);放到你的路由文件里,有什么问题?
    猜你喜欢
    • 1970-01-01
    • 2016-07-14
    • 2017-06-17
    • 2016-10-20
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    相关资源
    最近更新 更多