Open
Description
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