0

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.

Server log:

|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                                              |
+--------------+---------------------------------------------------------+

Component:

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

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

1 Answers1

0

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

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.

Oliver Adria
  • 1,023
  • 9
  • 21
  • Since it uses a placeholder with no prefix, yes, the priority seems to be the issue, it will match any request. But it's the other way around, the priority of the `index` route should be _lower_. – msg Nov 06 '20 at 13:17
  • You can also use a negative integer. – Oliver Adria Nov 06 '20 at 14:45
  • Yes, but that's a pretty important part of the answer, I commented to give you a chance to edit that in, as otherwise your suggestion won't do anything to solve the problem. – msg Nov 06 '20 at 14:55
  • Very interesting. I don't know about route priorities. I dealt with UserController, error still here. Then I set DefaultController:index path to priority -10 as suggested. Error still persists – Pavel Šrytr Nov 07 '20 at 19:02