{"record":{"id":"053ada23d92448a4","repo":"symfony/routing","slug":"route-s-with-locale-s-is-missing-a-corresponding-host-in-its","errorCode":null,"errorMessage":"Route \"%s\" with locale \"%s\" is missing a corresponding host in its parent collection.","messagePattern":"Route \"(.+?)\" with locale \"(.+?)\" is missing a corresponding host in its parent collection\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/Configurator/Traits/HostTrait.php","lineNumber":42,"sourceCode":"            $routes->setHost($hosts ?: '');\n\n            return;\n        }\n\n        foreach ($routes->all() as $name => $route) {\n            if (null === $locale = $route->getDefault('_locale')) {\n                $priority = $routes->getPriority($name) ?? 0;\n                $routes->remove($name);\n                foreach ($hosts as $locale => $host) {\n                    $localizedRoute = clone $route;\n                    $localizedRoute->setDefault('_locale', $locale);\n                    $localizedRoute->setRequirement('_locale', preg_quote($locale));\n                    $localizedRoute->setDefault('_canonical_route', $name);\n                    $localizedRoute->setHost($host);\n                    $routes->add($name.'.'.$locale, $localizedRoute, $priority);\n                }\n            } elseif (!isset($hosts[$locale])) {\n                throw new \\InvalidArgumentException(\\sprintf('Route \"%s\" with locale \"%s\" is missing a corresponding host in its parent collection.', $name, $locale));\n            } else {\n                $route->setHost($hosts[$locale]);\n                $route->setRequirement('_locale', preg_quote($locale));\n                $routes->add($name, $route, $routes->getPriority($name) ?? 0);\n            }\n        }\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":51,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/Configurator/Traits/HostTrait.php#L24-L51","documentation":"When applying localized hosts, HostTrait::addHost() requires every locale used by a child route to have a matching host defined in the parent collection's 'host' locale map. If a child route declares a locale whose host is absent from $hosts, an InvalidArgumentException is thrown so misconfigured localized hosts fail fast.","triggerScenarios":"Calling ->route()/->collection() with localized paths for a locale not present in the parent's ->host(['en' => ..., 'fr' => ...]) map, i.e. a route locale key missing from the parent hosts array.","commonSituations":"Adding a new language to route paths but forgetting to add the corresponding host entry in the parent collection; typos in locale codes ('fr-FR' vs 'fr'); mixing host- and prefix-based localization inconsistently.","solutions":["Add the missing locale to the parent's host map: ->host(['en' => 'en.example.com', 'fr' => 'fr.example.com']).","Fix locale key mismatches (typos, case, subtags) between the child route and parent hosts array.","If the locale should not be host-localized, remove it from the child route's localized paths."],"exampleFix":"// before\n$collection->host(['en' => 'en.example.com'])\n    ->route('home', ['en' => '/', 'fr' => '/accueil']);\n// after\n$collection->host(['en' => 'en.example.com', 'fr' => 'fr.example.com'])\n    ->route('home', ['en' => '/', 'fr' => '/accueil']);","handlingStrategy":"validation","validationCode":"$missing = array_diff(array_keys($routePaths), array_keys($parentHosts));\nif ($missing) { throw new \\LogicException('Add hosts for locales: ' . implode(',', $missing)); }","typeGuard":null,"tryCatchPattern":"try { $collection->host($hosts)->route(...); } catch (\\InvalidArgumentException $e) { /* log which locale/host pair is missing */ }","preventionTips":["Keep a single canonical locale list and derive both host and prefix maps from it.","Verify every child route locale exists in the parent host map before import.","Watch locale subtag mismatches (fr vs fr-FR)."],"tags":["routing","i18n","host","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"}