symfony/routing · error · LogicException

Route to " " with locale " " is missing a corresponding…

Error message

Route to "%s" with locale "%s" is missing a corresponding prefix in class "%s".

What it means

The inverse of error 31: when path and prefix are both localized arrays, each path locale must have a prefix locale. If a path locale has no corresponding prefix key, addRoute throws LogicException naming the method, locale and class.

Solutions

  1. Add the missing locale to the class-level #[Route] prefix array
  2. Or remove the extra locale from the method's localized path
  3. Keep the class prefix and method path locale key sets identical

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Method declares path: ['en' => '/blog', 'nl' => '/blog'] while the class #[Route] prefix only has ['en' => '/en'] — the 'nl' path locale has no prefix.

Common situations: Adding a locale to an action path without updating the controller-level prefix array; inconsistent translation files across class and method attributes.

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

Appendix: source

Thrown at Loader/AttributeClassLoader.php:186

        $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) {
            if (isset($defaults[$param->name]) || !$param->isDefaultValueAvailable()) {
                continue;
            }
            foreach ($paths as $locale => $path) {

View on GitHub (pinned to 83fa223250)