symfony: New #[Route] attribute parameter `alias` does not work for localized routes
Symfony version(s) affected
7.3.0
Description
I’m trying to use the new alias introduced on the #[Route] attribute in 7.3, but getting unexpected results.
How to reproduce
with configuration
# config/routing.yaml
general:
resource: '../src/Controller/'
type: attribute
prefix:
nl_NL: /
nl_BE: /
fr_FR: /
fr_BE: /fr
en_US: /
host:
nl_NL: '%nl_host%'
nl_BE: '%be_host%'
fr_FR: '%fr_host%'
fr_BE: '%be_host%'
en_US: '%en_host%'
using
#[Route(path: [
'nl_NL' => '/',
'nl_BE' => '/',
'fr_FR' => '/',
'fr_BE' => '/',
'en_US' => '/',
], name: 'default', methods: ['GET'], alias: ['my-alias'])]
yields Target route "default" for alias "my-alias" does not exist. from the template where i try to generate url(app.current_route)
but using
#[Route(path: '/', name: 'default', methods: ['GET'], alias: ['my-alias'])]
yields Unable to generate a URL for the named route "my-alias" as such route does not exist. later on in the same template when trying to generate url('my-alias')
Possible Solution
No response
Additional Context
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15 (15 by maintainers)
If aliases don’t work for other formats either, I suggest we document that limitation (and maybe add a better exception if possible) for 7.3, and that finding a way to support localized aliases gets handled as a new feature in a next minor version.
Ah rats, nevermind. Trying to write out a test scenario I actually discovered that this is probably not possible because the alias will only point to the last added locale of a route. There cannot be an alias for each localized entry because the alias entry is not localized and has to be unique.
Looks like the implementation of the
aliasproperty of the attribute has forgotten to consider the case of localized routes.