symfony/routing · error · LogicException

Route " " is missing routes for locale(s) " ".

Error message

Route "%s" is missing routes for locale(s) "%s".

What it means

createLocalizedRoute() checks that when a parent collection defines localized prefixes, the route's array of paths covers exactly those locales. If any prefix locale has no corresponding path in the route's array, a LogicException is thrown listing the missing locales.

Solutions

  1. Provide a path entry for every locale defined in the parent prefix map.
  2. Remove locales from the parent prefix that the route intentionally does not support.
  3. Use a scalar path (non-localized) if per-locale paths are not required.

Example fix

// before
->prefix(['en' => '/en', 'fr' => '/fr'])
    ->route('home', ['en' => '/']);
// after
->prefix(['en' => '/en', 'fr' => '/fr'])
    ->route('home', ['en' => '/', 'fr' => '/']);
Defensive patterns

Strategy: validation

Validate before calling

$missing = array_diff_key($prefixes, $paths);
if ($missing) { throw new \LogicException('Route is missing paths for: ' . implode(',', array_keys($missing))); }

Try / catch

try { $cfg->add($name, $paths); } catch (\LogicException $e) { /* supply paths for listed locales */ }

Prevention

When it happens

Trigger: Parent configured with ->prefix(['en' => '/en', 'fr' => '/fr']) but child route called with a partial path array, e.g. ->route('home', ['en' => '/']) missing 'fr'.

Common situations: Adding a new locale to the parent prefix map without updating every localized route; copying route definitions between projects with different locale sets; localized imports where one child omits a language.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/822f60553717d9c3. Report an issue: GitHub.

Appendix: source

Thrown at Loader/Configurator/Traits/LocalizedRouteTrait.php:40

 */
trait LocalizedRouteTrait
{
    /**
     * Creates one or many routes.
     *
     * @param string|array $path the path, or the localized paths of the route
     */
    final protected function createLocalizedRoute(RouteCollection $collection, string $name, string|array $path, string $namePrefix = '', ?array $prefixes = null): RouteCollection
    {
        $paths = [];

        $routes = new RouteCollection();

        if (\is_array($path)) {
            if (null === $prefixes) {
                $paths = $path;
            } elseif ($missing = array_diff_key($prefixes, $path)) {
                throw new \LogicException(\sprintf('Route "%s" is missing routes for locale(s) "%s".', $name, implode('", "', array_keys($missing))));
            } else {
                foreach ($path as $locale => $localePath) {
                    if (!isset($prefixes[$locale])) {
                        throw new \LogicException(\sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
                    }

                    $paths[$locale] = $prefixes[$locale].$localePath;
                }
            }
        } elseif (null !== $prefixes) {
            foreach ($prefixes as $locale => $prefix) {
                $paths[$locale] = $prefix.$path;
            }
        } else {
            $routes->add($namePrefix.$name, $route = $this->createRoute($path));
            $collection->add($namePrefix.$name, $route);

            return $routes;

View on GitHub (pinned to 83fa223250)