{"record":{"id":"56b4025bd5616ca8","repo":"dotnet/aspnetcore","slug":"the-routeview-component-requires-a-non-null-value","errorCode":null,"errorMessage":"The RouteView component requires a non-null value for the parameter RouteData.","messagePattern":"The RouteView component requires a non-null value for the parameter RouteData\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/RouteView.cs","lineNumber":60,"sourceCode":"    /// and accept a parameter named <see cref=\"LayoutComponentBase.Body\"/>.\n    /// </summary>\n    [Parameter]\n    public Type DefaultLayout { get; set; }\n\n    /// <inheritdoc />\n    public void Attach(RenderHandle renderHandle)\n    {\n        _renderHandle = renderHandle;\n    }\n\n    /// <inheritdoc />\n    public Task SetParametersAsync(ParameterView parameters)\n    {\n        parameters.SetParameterProperties(this);\n\n        if (RouteData == null)\n        {\n            throw new InvalidOperationException($\"The {nameof(RouteView)} component requires a non-null value for the parameter {nameof(RouteData)}.\");\n        }\n\n        _renderHandle.Render(Render);\n        return Task.CompletedTask;\n    }\n\n    /// <summary>\n    /// Renders the component.\n    /// </summary>\n    /// <param name=\"builder\">The <see cref=\"RenderTreeBuilder\"/>.</param>\n    [UnconditionalSuppressMessage(\"Trimming\", \"IL2110\", Justification = \"Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.\")]\n    [UnconditionalSuppressMessage(\"Trimming\", \"IL2111\", Justification = \"Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.\")]\n    [UnconditionalSuppressMessage(\"Trimming\", \"IL2118\", Justification = \"Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.\")]\n    protected virtual void Render(RenderTreeBuilder builder)\n    {\n        var pageLayoutType = _layoutAttributeCache\n            .GetOrAdd(RouteData.PageType, static type => type.GetCustomAttribute<LayoutAttribute>()?.LayoutType)\n            ?? DefaultLayout;","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/RouteView.cs#L42-L78","documentation":"Thrown in RouteView.SetParametersAsync. RouteView is the component that renders the matched page inside its layout; it requires RouteData (the matched page type + route values). If the parameter is still null after SetParameterProperties, RouteView cannot know which page to render and aborts.","triggerScenarios":"Rendering <RouteView> without a RouteData parameter, or passing RouteData=\"@null\". Typically RouteView is rendered from a Router's Found template as <RouteView RouteData=\"@routeData\" ...>; omitting RouteData or a Router that never supplies it triggers this.","commonSituations":"A custom Router Found template that renders <RouteView> but forgets to forward RouteData; using RouteView standalone without wiring it to a Router; a refactor that renamed/removed the RouteData binding.","solutions":["Always pass RouteData to RouteView in the Found template: <Found>...<RouteView RouteData=\"@routeData\" DefaultLayout=\"@typeof(MainLayout)\"/>...</Found>.","If using RouteView directly, ensure a non-null RouteData is constructed and bound.","Confirm the enclosing Router actually invokes Found with a valid RouteData."],"exampleFix":"<!-- before -->\n<Found Context=\"routeData\">\n    <RouteView DefaultLayout=\"@typeof(MainLayout)\" />\n</Found>\n\n<!-- after -->\n<Found Context=\"routeData\">\n    <RouteView RouteData=\"@routeData\" DefaultLayout=\"@typeof(MainLayout)\" />\n</Found>","handlingStrategy":"validation","validationCode":"// In the Router Found template, always forward RouteData to RouteView.\n<Found Context=\"routeData\">\n    @if (routeData is null) throw new InvalidOperationException(\"Router supplied null RouteData\");\n    <RouteView RouteData=\"@routeData\" DefaultLayout=\"@typeof(MainLayout)\" />\n</Found>","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always bind RouteData on <RouteView> inside the <Found> template.","Treat RouteData as [EditorRequired] — the IDE warns if omitted.","If you author a custom RouteView subclass, preserve the RouteData parameter binding."],"tags":["blazor","routing","routeview","routedata","missing-parameter"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}