问题描述
我在webpack上使用react + symfony。一切都可以使用简单的网址,例如。网址中的斜线(“ / aboutus” ,“ / moodle” ),但是当我尝试使用多个斜线(“ // admin / users” )我收到 NotFoundResource 错误。但是有了router:match
,我就会找到它。
服务器日志:
|WARN | SERVER GET (404) /admin/users
|ERROR| REQUES Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /admin/users"" at /home/rtkpf/Programming/Niners/vendor/symfony/http-kernel/EventListener/RouterListener.PHP line 136
router:match / admin / users
(master) [1]> bin/console router:match /admin/users
[OK] Route "index" matches
+--------------+---------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------+
| Route Name | index |
| Path | /{reactRouting} |
| Path Regex | {^/(?P<reactRouting>.+)?$}sDu |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | GET |
| Requirements | reactRouting: .+ |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: App\Controller\UserController::index() |
| | reactRouting: NULL |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | utf8: true |
+--------------+---------------------------------------------------------+
组件:
class DefaultController extends AbstractController
{
/**
* @Route("/{reactRouting}",name="index",defaults={"reactRouting": null},methods="GET",requirements={"reactRouting":".+"})
*/
public function index()
{
return $this->render('default/index.html.twig');
}
}
有人曾经经历过吗?哪里可能出错? 附注:我正在使用symfony服务器
解决方法
它在路由器:匹配中显示App\Controller\UserController::index()
,而您的控制器显示DefaultController
时,这可能是问题吗?
也可能存在优先级问题,因为5.1可以在路由中使用优先级(https://symfony.com/blog/new-in-symfony-5-1-route-annotations-priority),也许可以尝试在路由器注释中添加priority=-10,
使其优先级较低(默认为0)或{ {1}},如果您想在其他地方增加优先级。