{"record":{"id":"0d52cd1eefbf30a9","repo":"dotnet/aspnetcore","slug":"no-component-found-for-route-route-ensure-the","errorCode":null,"errorMessage":"No component found for route '{route}'. Ensure the route matches a component with a [Route] attribute.","messagePattern":"No component found for route '(.+?)'\\. Ensure the route matches a component with a \\[Route\\] attribute\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Routing/Router.cs","lineNumber":416,"sourceCode":"                _renderHandle.Render(builder => RenderComponentByRoute(builder, args.Path));\n            }\n            else\n            {\n                // Having the path set signals to the endpoint renderer that router handled rendering.\n                args.Path = _notFoundPageRoute;\n                RenderNotFound();\n            }\n            Log.DisplayingNotFound(_logger, args.Path);\n        }\n    }\n\n    internal void RenderComponentByRoute(RenderTreeBuilder builder, string route)\n    {\n        var componentType = FindComponentTypeByRoute(route);\n\n        if (componentType is null)\n        {\n            throw new InvalidOperationException($\"No component found for route '{route}'. \" +\n                $\"Ensure the route matches a component with a [Route] attribute.\");\n        }\n\n        builder.OpenComponent<RouteView>(0);\n        builder.AddAttribute(1, nameof(RouteView.RouteData),\n            new RouteData(componentType, new Dictionary<string, object>()));\n        builder.CloseComponent();\n    }\n\n    [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]\n    internal Type? FindComponentTypeByRoute(string route)\n    {\n        RefreshRouteTable();\n        var normalizedRoute = route.StartsWith('/') ? route : $\"/{route}\";\n\n        var context = new RouteContext(normalizedRoute);\n        Routes.Route(context);\n","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Routing/Router.cs#L398-L434","documentation":"Thrown by Blazor's Router when RenderComponentByRoute is asked to render a route that resolves to no component. RenderComponentByRoute calls FindComponentTypeByRoute, which normalizes the route, runs it through the compiled RouteTable, and returns null if no @page/[Route] handler matches. This InvalidOperationException surfaces during the NotFound/redirect flow when a subscriber sets a path that the router cannot resolve. It indicates a mismatch between the URL being navigated and the set of routable components discovered at startup.","triggerScenarios":"Calling NavigationManager.NavigateTo or having the Router render a path that no component declares with @page \"/that/path\". Triggered specifically via the OnNotFound path where args.Path is non-empty and _renderHandle is initialized, invoking RenderComponentByRoute(builder, args.Path) which returns a null componentType. Also reproducible when a route is built dynamically or the RouteContext.Handler is null because the matched type does not implement IComponent.","commonSituations":"A page was renamed/removed but a link still points at the old URL; the App.razor NotFound template or a custom router subscriber hands a path to the router that has no @page directive; per-page interactivity misconfiguration routes to a component living only in the .Client project that wasn't included in the route discovery assembly; case-sensitivity or trailing-slash differences between the link and the @page literal.","solutions":["Verify the failing route has a matching @page \"/exact/path\" or [Route(\"/exact/path\")] attribute on a component that implements IComponent.","If the component lives in a separate assembly/project, register it in Router.AppData with additional assemblies or confirm Routes is discovered via the right render mode.","Match the exact casing and leading slash — FindComponentTypeByRoute only prepends '/' when absent, it does not case-fold or strip trailing slashes.","If the route is legitimately absent, route to a NotFound page by leaving args.Path empty rather than passing the unknown path to RenderComponentByRoute.","Run the app with Microsoft.AspNetCore.Components logging at Debug to see which normalized route string is failing to resolve."],"exampleFix":"// before\n<Router AppAssembly=\"@typeof(Program).Assembly\">\n    <Found>...</Found>\n    <NotFound><p>Not found</p></NotFound>\n</Router>\n// navigation to /old-page that no longer exists throws during OnNotFound\n\n// after — add the page or redirect\n@page \"/old-page\"\n@page \"/new-page\"\n<NewPageContent />","handlingStrategy":"validation","validationCode":"// Before navigating, confirm the route is registered with the router.\nvar routeCollection = Router?.Routes; // access via reflection if needed, or maintain a known route set\nif (NavigationManager.Uri.StartsWith(NavigationManager.BaseUri))\n{\n    var rel = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);\n    // validate against your declared @page list before RenderComponentByRoute is invoked\n    if (!KnownRoutes.Contains(\"/\" + rel.Split('?')[0]))\n    {\n        NavigationManager.NavigateTo(\"/not-found\");\n    }\n}","typeGuard":"// Narrow route strings to a known-good set\nprivate static readonly HashSet<string> ValidRoutes = new()\n{\n    \"/\", \"/counter\", \"/fetchdata\"\n};\nstatic bool IsValidRoute(string? route) =>\n    route is not null && ValidRoutes.Contains(route.StartsWith('/') ? route : \"/\" + route);","tryCatchPattern":"// Wrap any external subscriber that sets args.Path in OnNotFound\ntry\n{\n    _renderHandle.Render(builder => RenderComponentByRoute(builder, requestedPath));\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No component found for route\"))\n{\n    // fall back to the NotFound template instead of crashing the circuit\n    RenderNotFound();\n}","preventionTips":["Maintain a unit-test-verified list of @page literals and assert every NavigateTo target is in it.","Configure a Router NotFound template and avoid passing unknown paths to RenderComponentByRoute.","Run link-checking as part of CI to catch removed pages.","When removing a page, add a redirect component at the old @page route."],"tags":["blazor","routing","navigation","invalidoperationexception"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}