Skip to content

NotFound route causes reload #23100

@TheOnlyBeardedBeast

Description

@TheOnlyBeardedBeast

Describe the bug

Hi!

When using Blazor wasm, the not found route causes browser page reload, happens even in the clear visual studio template.

To Reproduce

Create a new blazor wasm(clientside) app with the create a navlink which has a href attribute value a non existing page path. When you click on that navlink it navigates to the right url, but the whole app reloads, like you would open the app on a new page or tab e.g. the loading text shows up then it shows the notfound component.

The router config:

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>

Short time solution

I created a page which catches any page which is not defined but it only works for one path segment

@page "/{Path}"

<h1>@Path not found </h1>

@code{
    [Parameter]
    public string Path { get; set; }
}

for multiple segment paths I would need to define every segment manually because wildcards are not allowed

From the docs:
Catch-all parameter syntax (*/**) is not supported in Razor components (.razor).
https://docs.microsoft.com/en-us/aspnet/core/blazor/routing?view=aspnetcore-3.1#routing-with-urls-that-contain-dots

Further technical details

Visual Studio 2019
dotnet core version 3.1.300

info from the csproj:

<PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
    <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest></PropertyGroup>

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions