Skip to content

Blazor Router NotFoundPage incompatible with OnNavigateAsync #63933

@peterthorpe81

Description

@peterthorpe81

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The new NotFoundPage parameter in the Router component for blazor doesn't appear to work if you use it in conjunction with OnNavigateAsync. This is normally where I would delay load assemblies.

Expected Behavior

OnNavigateAsync shouldn't block the NotFoundPage functionality.

Steps To Reproduce

  1. Create a new project "dotnet new blazor"
  2. Launch the project and navigate to an invalid route, the not-found page is rendered.
  3. Modify the Routes.razor file to add use of OnNavigateAsync like below
<Router AppAssembly="typeof(Program).Assembly" OnNavigateAsync="OnNavigateAsync" NotFoundPage="typeof(Pages.NotFound)">
    <Found Context="routeData">
        <RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
        <FocusOnNavigate RouteData="routeData" Selector="h1" />
    </Found>
</Router>

@code {
    private async Task OnNavigateAsync(NavigationContext args)
    {
        await Task.Yield();
    }
}
  1. Launch the project and observe an invalid route results in a blank page

Exceptions (if any)

No response

.NET Version

10.0.100-rc.1.25451.107

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions