symfony/routing · error · InvalidArgumentException
The Router does not support the following options
Error message
The Router does not support the following options: "%s".
What it means
Router::setOptions() validates each option key against the set the Router supports (e.g. cache_dir, debug, resource_type, matcher...). Unknown keys are collected and, if any exist, an InvalidArgumentException listing them is thrown, typically from __construct(['bad_option' => ...]) or setOptions().
Solutions
- Fix the option key spelling against Router::setOptions/available options (cache_dir, debug, generator_class, matcher_class, matcher_base_class, matcher_dumper_class, matcher_cache_class, generator_base_class, generator_dumper_class, generator_cache_class, resource_type).
- Remove unsupported options; they may belong to a different router implementation (e.g. FrameworkBundle's router).
- Check the exception message — it lists exactly which keys are invalid.
- If the option existed in an older Symfony version, consult the UPGRADE notes for the renamed replacement.
Example fix
// before $router = new Router($container, 'routes.yaml', ['cacheDdir' => '/tmp/cache']); // after $router = new Router($container, 'routes.yaml', ['cache_dir' => '/tmp/cache']);
Defensive patterns
Strategy: validation
Validate before calling
$supported = ['cache_dir','debug','resource_type','matcher_class','matcher_base_class','matcher_dumper_class','matcher_cache_class','generator_class','generator_base_class','generator_dumper_class','generator_cache_class'];
$invalid = array_diff(array_keys($options), $supported);
if ($invalid) {
throw new \InvalidArgumentException('Unsupported router options: '.implode(', ', $invalid));
} Try / catch
try {
$router = new Router($container, $resource, $options);
} catch (\InvalidArgumentException $e) {
// inspect message for the listed invalid keys and fix config
} Prevention
- Copy option names from the Router class source or IDE autocomplete, never by hand from memory.
- Centralize router option construction in one factory method with a whitelist.
- When upgrading Symfony, diff option names against the UPGRADE notes.
When it happens
Trigger: new Router($container, $resource, ['cacheDdir' => $dir]) (typo), or passing framework-bundle-specific options (like 'cache_dir' misspelled, or options belonging to a different router class) to Symfony's Router.
Common situations: Typos in option names in the router service configuration; copying options from another routing library; upgrading Symfony where an option was renamed or removed.
Related errors
- The Router does not support the
- Cannot use UTF-8 route patterns without setting the "utf8"…
- Parameter " " for route " " must match " " (" " given) to…
- Parameters for route
- Route aliases cannot be used on non-invokable class
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/8214d0fabd524621.
Report an issue: GitHub.
Appendix: source
Thrown at Router.php:108
'generator_dumper_class' => CompiledUrlGeneratorDumper::class,
'matcher_class' => CompiledUrlMatcher::class,
'matcher_dumper_class' => CompiledUrlMatcherDumper::class,
'resource_type' => null,
'strict_requirements' => true,
];
// check option names and live merge, if errors are encountered Exception will be thrown
$invalid = [];
foreach ($options as $key => $value) {
if (\array_key_exists($key, $this->options)) {
$this->options[$key] = $value;
} else {
$invalid[] = $key;
}
}
if ($invalid) {
throw new \InvalidArgumentException(\sprintf('The Router does not support the following options: "%s".', implode('", "', $invalid)));
}
}
/**
* Sets an option.
*
* @throws \InvalidArgumentException
*/
public function setOption(string $key, mixed $value): void
{
if (!\array_key_exists($key, $this->options)) {
throw new \InvalidArgumentException(\sprintf('The Router does not support the "%s" option.', $key));
}
$this->options[$key] = $value;
}
/**View on GitHub (pinned to 83fa223250)