【问题标题】:Laravel - Duplicated RoutesLaravel - 重复的路线
【发布时间】:2017-06-15 10:42:48
【问题描述】:

在我的例子中,我创建了两个 Routes 像这样:

路线一:Route::get('/{title}',[ 'as' => 'projects', 'uses' => 'FrontendController@show' ]);

路线2:Route::get('/test', function (){ return 'Route test'; });

然后当我尝试在 Route 2 重定向:

http://localhost:8000/test

我得到Route 1的相同结果。他把 /test 当作 Route 1 的参数,但 /test 是另一个 Route。请帮忙

【问题讨论】:

    标签: laravel-5 routing routes


    【解决方案1】:

    将路由 2 移到路由 1 上方。路由 1 将尝试将任何可能匹配的内容绑定到 {title} 参数。您的路线文件应如下所示:

    Route::get('/test', function (){
        return 'Route test';
    });
    
    Route::get('/{title}',[
        'as' => 'projects',
        'uses' => 'FrontendController@show'
    ]);
    

    这样 /test 将在 /{title} 有机会消费它之前匹配。

    【讨论】:

      猜你喜欢
      • 2015-02-11
      • 2021-08-06
      • 1970-01-01
      • 2020-08-24
      • 2019-01-12
      • 2016-05-03
      • 2021-04-05
      • 2020-12-04
      • 2017-11-30
      相关资源
      最近更新 更多