dotnet/aspnetcore · error · InvalidOperationException
The RouteView component requires a non-null value for the pa
Error message
The RouteView component requires a non-null value for the parameter RouteData.
What it means
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.
Source
Thrown at src/Components/Components/src/RouteView.cs:60
/// and accept a parameter named <see cref="LayoutComponentBase.Body"/>.
/// </summary>
[Parameter]
public Type DefaultLayout { get; set; }
/// <inheritdoc />
public void Attach(RenderHandle renderHandle)
{
_renderHandle = renderHandle;
}
/// <inheritdoc />
public Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
if (RouteData == null)
{
throw new InvalidOperationException($"The {nameof(RouteView)} component requires a non-null value for the parameter {nameof(RouteData)}.");
}
_renderHandle.Render(Render);
return Task.CompletedTask;
}
/// <summary>
/// Renders the component.
/// </summary>
/// <param name="builder">The <see cref="RenderTreeBuilder"/>.</param>
[UnconditionalSuppressMessage("Trimming", "IL2110", Justification = "Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.")]
[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.")]
[UnconditionalSuppressMessage("Trimming", "IL2118", Justification = "Layout components are preserved because the LayoutAttribute constructor parameter is correctly annotated.")]
protected virtual void Render(RenderTreeBuilder builder)
{
var pageLayoutType = _layoutAttributeCache
.GetOrAdd(RouteData.PageType, static type => type.GetCustomAttribute<LayoutAttribute>()?.LayoutType)
?? DefaultLayout;View on GitHub (pinned to 294cab2f9b)
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.
Example fix
<!-- before -->
<Found Context="routeData">
<RouteView DefaultLayout="@typeof(MainLayout)" />
</Found>
<!-- after -->
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found> Defensive patterns
Strategy: validation
Validate before calling
// In the Router Found template, always forward RouteData to RouteView.
<Found Context="routeData">
@if (routeData is null) throw new InvalidOperationException("Router supplied null RouteData");
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found> Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The value must implement IComponent.
- The Router component requires a value for the parameter AppA
- The Router component requires a value for the parameter Foun
- The following routes are ambiguous: '{existingText}' in '{ex
- Setting NotFound and NotFoundPage properties simultaneously
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/56b4025bd5616ca8.
Report an issue: GitHub.