{"record":{"id":"70a09a30a08812c9","repo":"dotnet/aspnetcore","slug":"the-nameof-routeview-component-requires-a-non-n","errorCode":null,"errorMessage":"The {nameof(RouteView)} component requires a non-null value for the parameter {nameof(RouteData)}.","messagePattern":"The (.+?) component requires a non-null value for the parameter (.+?)\\.","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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/RouteView.cs#L42-L78","documentation":"RouteView is the component that renders the matched page inside a Router; it reads its RouteData parameter and dispatches to the page component described there. A null RouteData is a configuration error: RouteView has nothing to render and cannot guess one, so SetParametersAsync throws InvalidOperationException before requesting a render. The contract is that the host (Router) always supplies RouteData.","triggerScenarios":"Declaring <RouteView /> in markup without a RouteData parameter, or binding RouteData to an expression that evaluates to null. Also triggered by manually constructing a RouteView and calling SetParametersAsync with a ParameterView that omits RouteData.","commonSituations":"Removing the @bind or [Parameter] wiring for RouteData in a custom App.razor; a typo in the parameter name causing null binding; using RouteView outside a Router without supplying RouteData manually; reflection-based component activation that skips the parameter.","solutions":["Confirm RouteView is always rendered with a non-null RouteData — typically <RouteView RouteData=\"@routeData\" /> inside the Router's Found template.","If using RouteView standalone, pass a RouteData constructed from a known page type.","Audit the Found render fragment on the parent Router to ensure routeData (the lambda parameter) is forwarded, not shadowed.","Add a null check at the call site and fall back to a known route rather than letting RouteView receive null."],"exampleFix":"// before (App.razor)\n<Found Context=\"routeData\">\n    <RouteView />  <!-- RouteData omitted, throws -->\n</Found>\n\n// after\n<Found Context=\"routeData\">\n    <RouteView RouteData=\"@routeData\" DefaultLayout=\"@typeof(MainLayout)\" />\n</Found>","handlingStrategy":"validation","validationCode":"// Before rendering RouteView (e.g. in a custom host), confirm RouteData is non-null.\nif (routeData is null)\n    throw new InvalidOperationException(\"RouteData must be supplied to RouteView.\");\nbuilder.OpenComponent<RouteView>(0);\nbuilder.AddAttribute(1, nameof(RouteView.RouteData), routeData);\nbuilder.CloseComponent();","typeGuard":"static bool IsValidRouteData(RouteData? d) => d?.PageType is not null;","tryCatchPattern":null,"preventionTips":["Always forward the Found lambda's routeData parameter to <RouteView RouteData=\"@routeData\" />.","When using RouteView standalone, construct a RouteData from a known page type before passing it.","Add a default value or guard in markup: @if (routeData is not null) { <RouteView RouteData=@routeData /> }.","Keep RouteView inside the Router's Found template."],"tags":["blazor","routing","routeview","parameter","invalidoperationexception"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}