Symfony5 在浏览器中抛出 404,但在 cli 中找到了路由 [英] Symfony5 throws 404 in browser, but route is found in cli

查看:46
本文介绍了Symfony5 在浏览器中抛出 404,但在 cli 中找到了路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 webpack 中使用 react+symfony.一切都适用于简单的网址,例如.url 中的一个斜杠(/aboutus",/moodle")但是当我尝试使用多个斜杠访问路由时(/admin/users";) 我收到 NotFoundResource 错误.但是使用 router:match 我会找到它.

Iam using react+symfony with webpack. Everything works with simple url eg. one slash in url ("/aboutus","/moodle") but when i try access route with multiple slashes("/admin/users") i get NotFoundResource Error. But with router:matchi will find it.

服务器日志:

|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 

路由器:匹配/admin/users

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');
    }
}

有人遇到过这种情况吗?哪里会出错?P.S.:我使用的是 symfony 服务器

Has someone experienced this before? Where can be a mistake? P.S.: Ia m using symfony server

推荐答案

它说 App\Controller\UserController::index() in router:match 而你的控制器显示 DefaultController,这是一个可能的问题吗?

It says App\Controller\UserController::index() in router:match while your controller shows DefaultController, is this a possible problem?

也可能存在优先级问题,因为 5.1 您可以在路由中使用优先级 (https://symfony.com/blog/new-in-symfony-5-1-route-annotations-priority),也许尝试添加priority=-10, 在路由器注释中将其优先级降低(默认为 0)或 priority=10, 以防您想在其他地方增加优先级.

There could also be a priority issue, since 5.1 you can use priorities in routing (https://symfony.com/blog/new-in-symfony-5-1-route-annotations-priority), perhaps try adding priority=-10, in the router annotation to prioritize it lower (0 is default) or priority=10, in case you want to increase the priority somewhere else.

这篇关于Symfony5 在浏览器中抛出 404,但在 cli 中找到了路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆