Laravel路由允许任何参数不起作用

时间:2018-04-24 11:49:10

标签: php laravel

任何帮助,为什么这不起作用,我使用Laravel 5.4版本,这是我的路线

应用\提供商\ RouteServiceProvider.php

public function map()
{
    $this->mapWebRoutes();
    $this->mapExampleRoutes();
}
protected function mapExampleRoutes()
{
    Route::prefix('example')
         ->middleware('example')
         ->namespace($this->namespace.'\\Examle')
         ->group(base_path('routes/example.php'));
}

路由\使用example.php

Route::get('/{any}', function () {
    return view('example.app');
})->where('any', '.*');

$ php artisan route:list

+--------+-----------+-----------------+------+----------+-------------+
| Domain | Method    | URI             | Name | Action   | Middleware  |
+--------+-----------+-----------------+------+----------+-------------+
|        | GET|HEAD  | /               |      | Closure  | web         |
|        | GET|HEAD  | example/{any}   |      | Closure  | example     |
+--------+-----------+-----------------+------+----------+-------------+

问题是当我尝试访问/示例时返回not found(NotFoundHttpException), 其他路由正在运行,例如/ example / login 知道为什么这个不起作用吗?

1 个答案:

答案 0 :(得分:0)

Route::get('{any?}', function () {
    return view('example.app');
})->where('any', '.*');

我删除了前导斜杠(/)并添加了一个问号(?)来表示slug是可选的。

相关问题