Skip to content

{_locale} parameter in routing not working with Symfony >= 4.4.8 #37602

Closed
@vincentjdc

Description

@vincentjdc

Hi,

I've a weird issue when using Symfony 4.4.8 or above.

A route defined with {_locale} parameter leads to a 404 route not found error.

I have the following routes defined

/**
 * @Route("/sites/{id}",
 *    name="site_get",
 *    methods={"GET"},
 *    requirements={"id": "\d+"},
 * )
 *
 * @Route("/{_locale}/sites/{id}",
 *    name="site_get_with_locale",
 *    methods={"GET"},
 *    requirements={"id": "\d+", "_locale": "fr|en"},
 * )
 *
 */

With Symfony 4.4.8

When calling /en/sites/1 I get a 404 error "route not found".
The debug:router show the defined routes :

site_get.0                                      GET         ANY      ANY    /api/sites/{id}                                                 
site_get_with_locale.0                          GET         ANY      ANY    /api/{_locale}/sites/{id} 

But the profiler gives a different routing configuration :
image

With Symfony 4.4.7

When calling /en/sites/1 everything is fine, I get the desired resource
The debug:router show the defined routes :

site_get.0                                      GET         ANY      ANY    /api/sites/{id}                                                 
site_get_with_locale.0                          GET         ANY      ANY    /api/{_locale}/sites/{id} 

And the profiler routing section :
image

I also wrote a post on stackoverflow :
https://stackoverflow.com/questions/62934810/symfony-4-setting-locale-parameter-in-route-definition-leads-to-no-route-f

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions