symfony/routing · error · RouteNotFoundException
Unable to generate a URL for the named route
Error message
Unable to generate a URL for the named route "%s" as such route does not exist.
What it means
UrlGenerator::generate() fetches the named route from the RouteCollection; this error means no route with that name (or locale-suffixed variant after the fallback loop) exists, so a URL cannot be generated.
Solutions
- Run `php bin/console debug:router` and copy the exact route name.
- Fix the name or register the missing route.
- Clear/warm the cache if the route was recently added.
- Catch RouteNotFoundException for graceful degradation.
Example fix
// before
$url = $generator->generate('user_profile');
// after
try {
$url = $generator->generate('user_profile');
} catch (RouteNotFoundException $e) {
$url = $generator->generate('homepage');
} Defensive patterns
Strategy: try-catch
Validate before calling
$names = array_keys($router->getRouteCollection()->all());
if (!in_array($name, $names, true)) {
return null;
} Type guard
function hasRoute(RouteCollectionInterface $routes, string $name): bool { return null !== $routes->get($name); } Try / catch
use Symfony\Component\Routing\Exception\RouteNotFoundException;
try { $url = $generator->generate($name); } catch (RouteNotFoundException $e) { $url = $generator->generate('fallback'); } Prevention
- Run debug:router before referencing new names
- Use route name constants or generated route classes
- Warm cache after route changes
- Provide locale fallbacks for localized route names
When it happens
Trigger: generate($name, ...) with $name absent from the collection; also after the locale fallback tries substrings of the name like 'route.en' → 'route' and still finds nothing.
Common situations: Route name typo; route registered in a different scope/bundle; localized route names where only some locales exist; stale container cache.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Unable to generate a URL for the named route
- Using "%% %%" is not allowed in routing configuration.
- The container parameter
- The container parameter
- Target route " " for alias " " does not exist.
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/a606ba1cac82902a.
Report an issue: GitHub.
Appendix: source
Thrown at Generator/UrlGenerator.php:119
return $this->strictRequirements;
}
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
$route = null;
$locale = $parameters['_locale'] ?? $this->context->getParameter('_locale') ?: $this->defaultLocale;
if (null !== $locale) {
do {
$route = $this->routes->get($name.'.'.$locale);
if ($route && ($route->getDefault('_canonical_route') === $name || $this->routes->getAlias($name.'.'.$locale))) {
break;
}
} while (false !== $locale = strstr($locale, '_', true));
}
if (null === $route ??= $this->routes->get($name)) {
throw new RouteNotFoundException(\sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
}
// the Route has a cache of its own and is not recompiled as long as it does not get modified
$compiledRoute = $route->compile();
$defaults = $route->getDefaults();
$variables = $compiledRoute->getVariables();
if (isset($defaults['_canonical_route']) && isset($defaults['_locale'])) {
if (!\in_array('_locale', $variables, true)) {
unset($parameters['_locale']);
} elseif (!isset($parameters['_locale'])) {
$parameters['_locale'] = $defaults['_locale'];
}
}
return $this->doGenerate($variables, $defaults, $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), $route->getSchemes());
}View on GitHub (pinned to 83fa223250)