![](/img/trans.png)
[英]Symfony 2. Route appears to work in CLI but always 404's in browser
[英]Symfony5 throws 404 in browser, but route is found in cli
我在 webpack 中使用 react+symfony。 一切都適用於簡單的網址,例如。 url 中的一個斜杠( “/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
路由器:匹配/管理員/用戶
(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');
}
}
以前有人經歷過嗎? 哪里會出錯? PS:我使用 symfony 服務器
它說App\\Controller\\UserController::index()
in router:match 而你的控制器顯示DefaultController
,這是一個可能的問題嗎?
也可能存在優先級問題,因為 5.1 您可以在路由中使用優先級( https://symfony.com/blog/new-in-symfony-5-1-route-annotations-priority ),也許嘗試添加priority=-10,
在路由器注釋中將其優先級較低(默認為0)或priority=10,
以防您想在其他地方增加優先級。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.