{"record":{"id":"db3f59b969166f83","repo":"symfony/routing","slug":"route-s-with-locale-s-is-missing-a-corresponding-prefix-in","errorCode":null,"errorMessage":"Route \"%s\" with locale \"%s\" is missing a corresponding prefix in its parent collection.","messagePattern":"Route \"(.+?)\" with locale \"(.+?)\" is missing a corresponding prefix in its parent collection\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Loader/Configurator/Traits/LocalizedRouteTrait.php","lineNumber":44,"sourceCode":"     * Creates one or many routes.\n     *\n     * @param string|array $path the path, or the localized paths of the route\n     */\n    final protected function createLocalizedRoute(RouteCollection $collection, string $name, string|array $path, string $namePrefix = '', ?array $prefixes = null): RouteCollection\n    {\n        $paths = [];\n\n        $routes = new RouteCollection();\n\n        if (\\is_array($path)) {\n            if (null === $prefixes) {\n                $paths = $path;\n            } elseif ($missing = array_diff_key($prefixes, $path)) {\n                throw new \\LogicException(\\sprintf('Route \"%s\" is missing routes for locale(s) \"%s\".', $name, implode('\", \"', array_keys($missing))));\n            } else {\n                foreach ($path as $locale => $localePath) {\n                    if (!isset($prefixes[$locale])) {\n                        throw new \\LogicException(\\sprintf('Route \"%s\" with locale \"%s\" is missing a corresponding prefix in its parent collection.', $name, $locale));\n                    }\n\n                    $paths[$locale] = $prefixes[$locale].$localePath;\n                }\n            }\n        } elseif (null !== $prefixes) {\n            foreach ($prefixes as $locale => $prefix) {\n                $paths[$locale] = $prefix.$path;\n            }\n        } else {\n            $routes->add($namePrefix.$name, $route = $this->createRoute($path));\n            $collection->add($namePrefix.$name, $route);\n\n            return $routes;\n        }\n\n        foreach ($paths as $locale => $path) {\n            $routes->add($name.'.'.$locale, $route = $this->createRoute($path));","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/Configurator/Traits/LocalizedRouteTrait.php#L26-L62","documentation":"The inverse check of the missing-locales case: the route's path array contains a locale key that the parent collection's prefix map does not define. createLocalizedRoute() throws a LogicException because it cannot build a full localized path without the parent prefix for that locale.","triggerScenarios":"Passing ['en' => '/', 'fr' => '/accueil'] to a route whose parent has only ->prefix(['en' => '/en']) (or a non-localized prefix); locale key typos ('fr-FR' in the route vs 'fr' in the prefix).","commonSituations":"Reusing route definitions across collections where one has full locale prefixes and another does not; adding a locale to a route before updating the parent prefix map.","solutions":["Add the missing locale to the parent's prefix map so it matches the route's locale keys.","Remove the extra locale from the route's path array.","Align locale codes exactly (including region subtags) between prefix and route arrays."],"exampleFix":"// before\n->prefix(['en' => '/en'])\n    ->route('home', ['en' => '/', 'fr' => '/accueil']);\n// after\n->prefix(['en' => '/en', 'fr' => '/fr'])\n    ->route('home', ['en' => '/', 'fr' => '/accueil']);","handlingStrategy":"validation","validationCode":"$extra = array_diff_key($paths, $prefixes);\nif ($extra) { throw new \\LogicException('Parent prefixes missing for: ' . implode(',', array_keys($extra))); }","typeGuard":null,"tryCatchPattern":"try { $cfg->add($name, $paths); } catch (\\LogicException $e) { /* add missing prefix or drop the locale */ }","preventionTips":["Derive route path arrays from the same locale keys used in prefix().","Audit route locale keys against the parent prefix map in CI.","Avoid hardcoding locale arrays per route."],"tags":["routing","i18n","localized-routes","symfony"],"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"}