{"record":{"id":"ee91ddd64758cf87","repo":"symfony/routing","slug":"route-to-s-with-locale-s-is-missing-a-corresponding-prefix","errorCode":null,"errorMessage":"Route to \"%s\" with locale \"%s\" is missing a corresponding prefix in class \"%s\".","messagePattern":"Route to \"(.+?)\" with locale \"(.+?)\" is missing a corresponding prefix in class \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Loader/AttributeClassLoader.php","lineNumber":186,"sourceCode":"        $host = $attr->host ?? $globals['host'];\n        $condition = $attr->condition ?? $globals['condition'];\n        $priority = $attr->priority ?? $globals['priority'];\n\n        $path = $attr->path;\n        $prefix = $globals['localized_paths'] ?: $globals['path'];\n        $paths = [];\n\n        if (\\is_array($path)) {\n            if (!\\is_array($prefix)) {\n                foreach ($path as $locale => $localePath) {\n                    $paths[$locale] = $prefix.$localePath;\n                }\n            } elseif ($missing = array_diff_key($prefix, $path)) {\n                throw new \\LogicException(\\sprintf('Route to \"%s\" is missing paths for locale(s) \"%s\".', $class->name.'::'.$method->name, implode('\", \"', array_keys($missing))));\n            } else {\n                foreach ($path as $locale => $localePath) {\n                    if (!isset($prefix[$locale])) {\n                        throw new \\LogicException(\\sprintf('Route to \"%s\" with locale \"%s\" is missing a corresponding prefix in class \"%s\".', $method->name, $locale, $class->name));\n                    }\n\n                    $paths[$locale] = $prefix[$locale].$localePath;\n                }\n            }\n        } elseif (\\is_array($prefix)) {\n            foreach ($prefix as $locale => $localePrefix) {\n                $paths[$locale] = $localePrefix.$path;\n            }\n        } else {\n            $paths[] = $prefix.$path;\n        }\n\n        foreach ($method->getParameters() as $param) {\n            if (isset($defaults[$param->name]) || !$param->isDefaultValueAvailable()) {\n                continue;\n            }\n            foreach ($paths as $locale => $path) {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/AttributeClassLoader.php#L168-L204","documentation":"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.","triggerScenarios":"Method declares path: ['en' => '/blog', 'nl' => '/blog'] while the class #[Route] prefix only has ['en' => '/en'] — the 'nl' path locale has no prefix.","commonSituations":"Adding a locale to an action path without updating the controller-level prefix array; inconsistent translation files across class and method attributes.","solutions":["Add the missing locale to the class-level #[Route] prefix array","Or remove the extra locale from the method's localized path","Keep the class prefix and method path locale key sets identical"],"exampleFix":"// before\n#[Route(path: ['en' => '/en'])]\nclass BlogController {\n  #[Route(path: ['en' => '/blog', 'nl' => '/blog'])]\n// after\n#[Route(path: ['en' => '/en', 'nl' => '/nl'])]\nclass BlogController {\n  #[Route(path: ['en' => '/blog', 'nl' => '/blog'])]","handlingStrategy":"validation","validationCode":"$missing = array_diff_key(array_keys($methodPath), array_keys($classPrefix)); if ($missing) { /* add prefixes before loading */ }","typeGuard":"function pathLocalesPrefixed(array $prefix, array $path): bool { return !array_diff_key($path, $prefix); }","tryCatchPattern":"try { $routes = $loader->load($file); } catch (\\LogicException $e) { /* path locale without prefix — sync attributes */ }","preventionTips":["Derive both prefix and path arrays from a single locale constant","Review new locales across class AND method attributes together","CI test that loads the full route tree"],"tags":["routing","i18n","localized-routes"],"backgroundTag":"missing-required-config-field","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}