Skip to content

Allow defining non-localized routes explicitly when using auto-prefixing #60367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
speller opened this issue May 7, 2025 · 0 comments
Open

Comments

@speller
Copy link

speller commented May 7, 2025

Description

Symfony allows configuring the auto-prefixing of all routes with a list of locales. But sometimes, while the vast majority of URLs should be localized, some of them should be neutral and avoid auto-prefixing.

The suggestion is to allow defining explicit exclusion of routes from auto-prefixing with the new Route attribute locale value: false:

--- a/Loader/Configurator/Traits/PrefixTrait.php
+++ b/Loader/Configurator/Traits/PrefixTrait.php
@@ -39,6 +39,9 @@
                         $localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
                         $routes->add($name.'.'.$locale, $localizedRoute, $priority);
                     }
+                } elseif (false === $locale) {
+                    // Explicitly non-prefixed non-localized route.
+                    $route->setDefault('_locale', null);
                 } elseif (!isset($prefix[$locale])) {
                     throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
                 } else {
--- a/Attribute/Route.php
+++ b/Attribute/Route.php
@@ -51,7 +51,7 @@
         array|string $schemes = [],
         private ?string $condition = null,
         private ?int $priority = null,
-        ?string $locale = null,
+        string|false|null $locale = null,
         ?string $format = null,
         ?bool $utf8 = null,
         ?bool $stateless = null,

With this patch, I'm able to configure routes like this:

    #[Route('/.well-known/jwks.json', name: 'public_jwks', methods: ['GET'], locale: false, stateless: true)]

This allows the route to be excluded from auto-prefixing and remain as-is.

Example

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants