路由里面的可选参数,怎么配置了就报错

a178251115

问题描述

路由里面配置了可选参数,配置了就报错
Route::any('/show[/area/{area}][/class/{class}][/id/{id}][/year/{year}][/page/{page}].html', [app\index\controller\Vod::class, 'show'])->name('vod/show');

FastRoute\BadRouteException: Optional segments can only occur at the end of a route in /www/wwwroot/webman/vendor/nikic/fast-route/src/RouteParser/Std.php:35
Stack trace:

0 /www/wwwroot/webman/vendor/nikic/fast-route/src/RouteCollector.php(41): FastRoute\RouteParser\Std->parse()

1 /www/wwwroot/webman/vendor/workerman/webman-framework/src/Route.php(382): FastRoute\RouteCollector->addRoute()

2 /www/wwwroot/webman/vendor/workerman/webman-framework/src/Route.php(171): Webman\Route::addRoute()

3 /www/wwwroot/webman/app/index/config/route.php(31): Webman\Route::any()

4 /www/wwwroot/webman/config/route.php(19): require_once('...')

5 /www/wwwroot/webman/vendor/workerman/webman-framework/src/Route.php(405): require_once('...')

6 /www/wwwroot/webman/vendor/nikic/fast-route/src/functions.php(25): Webman\Route::Webman{closure}()

7 /www/wwwroot/webman/vendor/workerman/webman-framework/src/Route.php(427): FastRoute\simpleDispatcher()

8 /www/wwwroot/webman/support/bootstrap.php(132): Webman\Route::load()

9 /www/wwwroot/webman/vendor/workerman/webman-framework/src/support/App.php(104): require_once('...')

10 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(2497): support\App::support{closure}()

11 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(1636): Workerman\Worker->run()

12 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(1429): Workerman\Worker::forkOneWorkerForLinux()

13 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(1403): Workerman\Worker::forkWorkersForLinux()

14 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(1788): Workerman\Worker::forkWorkers()

15 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(1724): Workerman\Worker::monitorWorkersForLinux()

16 /www/wwwroot/webman/vendor/workerman/workerman/Worker.php(562): Workerman\Worker::monitorWorkers()

17 /www/wwwroot/webman/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll()

18 /www/wwwroot/webman/start.php(4): support\App::run()

713 1 0
1个回答

nitron
Route::any('/show[/area/{area}][/class/{class}][/id/{id}][/year/{year}][/page/{page}]', [app\index\controller\Vod::class, 'show'])->name('vod/show');
  • a178251115 2024-02-29

    还是一样的错误,只能设置一个就没问题

  • nitron 2024-02-29
    Route::any('/show[/area/{area}[/class/{class}[/id/{id}[/year/{year}[/page/{page}]]]]]', [app\index\controller\Vod::class, 'show'])->name('vod/show');
  • a178251115 2024-02-29

    谢谢,启动不报错了,但是生成的url 还是报404,还是非常感谢

  • a178251115 2024-02-29

    上面的结果和整个用一个[]括起来是一样的,

×
🔝