dotnet/aspnetcore · error · InvalidOperationException
No component found for route
Error message
No component found for route '{route}'. Ensure the route matches a component with a [Route] attribute. What it means
RenderComponentByRoute resolves the requested route to a component type via FindComponentTypeByRoute; if no component in the configured assemblies declares a matching [Route], the type lookup returns null and the method throws InvalidOperationException with a hint to verify the [Route] attribute. This is the explicit failure mode for the programmatic render-by-route API (used by tests and Server/renderer entry points).
Solutions
- Confirm the route string exactly matches a [Route("...")] on a component, including leading slash and parameter placeholders.
- Add the assembly containing the page to AppAssembly / AdditionalAssemblies on the Router.
- If publishing with trimming, ensure the page type and its [Route] attribute are root-preserved (e.g. via DynamicallyAccessedMembers or a linker XML).
- Verify the page component compiles and its generated route attribute is present (check with reflection in a test).
Example fix
// before
renderer.RenderComponentByRoute("/usrs/42"); // typo
// after
renderer.RenderComponentByRoute("/users/42"); // matches [Route("/users/{id}")] Defensive patterns
Strategy: validation
Validate before calling
// Validate the route is known before invoking RenderComponentByRoute.
if (!knownRoutes.Contains(route, StringComparer.OrdinalIgnoreCase))
throw new InvalidOperationException($"No registered route matches '{route}'."); Try / catch
// Only meaningful in test harnesses; otherwise the route should already be validated.
try { renderer.RenderComponentByRoute(route); }
catch (InvalidOperationException ex) when (ex.Message.Contains("No component found for route"))
{
// log and fall back to a known route
} Prevention
- Keep a list of valid routes (derived from [Route] attributes) and validate before programmatic render.
- Include every page-bearing assembly in the Router configuration.
- When publishing trimmed, root-preserve page types and their [Route] attributes.
- Add a test enumerating routes and rendering each.
When it happens
Trigger: Calling RenderComponentByRoute (or an internal caller such as the test harness / pre-rendering pipeline) with a route string that matches no [Route] attribute in the scanned assemblies. Also triggered by navigation to a path before the page component has been registered (race with route table population).
Common situations: Programmatically rendering a component by URL in a test and mistyping the route; the target page is in an assembly not passed to the Router; the [Route] uses a parameter placeholder that does not match the supplied literal route; trimming removed the page or its [Route] attribute at publish time.
Related errors
- Setting and properties simultaneously is not supported. Use…
- The component requires a value for the parameter .
- The component requires a value for the parameter .
- The type does not implement .
- The type does not have a applied to it.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/0d52cd1eefbf30a9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/Routing/Router.cs:416
_renderHandle.Render(builder => RenderComponentByRoute(builder, args.Path));
}
else
{
// Having the path set signals to the endpoint renderer that router handled rendering.
args.Path = _notFoundPageRoute;
RenderNotFound();
}
Log.DisplayingNotFound(_logger, args.Path);
}
}
internal void RenderComponentByRoute(RenderTreeBuilder builder, string route)
{
var componentType = FindComponentTypeByRoute(route);
if (componentType is null)
{
throw new InvalidOperationException($"No component found for route '{route}'. " +
$"Ensure the route matches a component with a [Route] attribute.");
}
builder.OpenComponent<RouteView>(0);
builder.AddAttribute(1, nameof(RouteView.RouteData),
new RouteData(componentType, new Dictionary<string, object>()));
builder.CloseComponent();
}
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
internal Type? FindComponentTypeByRoute(string route)
{
RefreshRouteTable();
var normalizedRoute = route.StartsWith('/') ? route : $"/{route}";
var context = new RouteContext(normalizedRoute);
Routes.Route(context);
View on GitHub (pinned to 3600ca084e)