symfony/routing · error · LogicException

Route to " " is missing paths for locale(s) " ".

Error message

Route to "%s" is missing paths for locale(s) "%s".

What it means

When a route method path and the class-level prefix are both locale-keyed arrays, every prefix locale must have a matching path locale. addRoute uses array_diff_key to find prefix locales absent from the path array and throws LogicException listing the missing locales.

Solutions

  1. Add a path entry for every locale present in the class-level prefix
  2. Or remove the extra locale from the class-level #[Route] prefix
  3. Or make the method path non-localized (plain string) if localization is only needed at prefix level

Example fix

// before
#[Route(path: ['en' => '/en', 'nl' => '/nl'])]
class BlogController {
  #[Route(path: ['en' => '/blog'])]
  public function index() {}
}
// after
#[Route(path: ['en' => '/blog', 'nl' => '/blog'])]
  public function index() {}
Defensive patterns

Strategy: validation

Validate before calling

$missing = array_diff_key(array_keys($classPrefix), array_keys($methodPath)); if ($missing) { /* fix before loading */ }

Type guard

function localesMatch(array $prefix, array $path): bool { return !array_diff_key($prefix, $path); }

Try / catch

try { $routes = $loader->load($file); } catch (\LogicException $e) { /* missing locale path/prefix — fix route attributes */ }

Prevention

When it happens

Trigger: Class has #[Route(path: ['en' => '/en', 'nl' => '/nl'])] but the method declares a localized path missing some locales, e.g. path: ['en' => '/blog'] — the 'nl' prefix has no corresponding path.

Common situations: Adding a new locale to the class-level prefix without updating every localized action path; partially translated controllers; copy-pasting a localized route and deleting one locale entry.

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/0ed7641af16854ef. Report an issue: GitHub.

Appendix: source

Thrown at Loader/AttributeClassLoader.php:182

        $options = array_replace($globals['options'], $attr->options);
        $schemes = array_unique(array_merge($globals['schemes'], $attr->schemes));
        $methods = array_unique(array_merge($globals['methods'], $attr->methods));

        $host = $attr->host ?? $globals['host'];
        $condition = $attr->condition ?? $globals['condition'];
        $priority = $attr->priority ?? $globals['priority'];

        $path = $attr->path;
        $prefix = $globals['localized_paths'] ?: $globals['path'];
        $paths = [];

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

                    $paths[$locale] = $prefix[$locale].$localePath;
                }
            }
        } elseif (\is_array($prefix)) {
            foreach ($prefix as $locale => $localePrefix) {
                $paths[$locale] = $localePrefix.$path;
            }
        } else {
            $paths[] = $prefix.$path;
        }

        foreach ($method->getParameters() as $param) {

View on GitHub (pinned to 83fa223250)