Skip to content

NavLink does not update Route parameters in code #9931

Closed
@JonasPrimbs

Description

@JonasPrimbs

My .razor file looks as follows:

@page "/example"
@page "/example/{id}"

<h1>@ID</h1>
<NavLink href="/example/something">Something</NavLink>
<NavLink href="/example/">Nothing</NavLink>
<button onclick="@Show">Show</button>

@functions {
    [Parameter]
    public string ID { get; set; } = "Nothing";

    public void Show()
    {
        Console.WriteLine(ID);
    }
}

When I navigate to /example, the h1 tag contains "Nothing", as expected. If I now click on the NavLink "Something", the h1 tag contains "Something", also as expected.
But if I then click on the NavLink "Nothing", the URL in browser changes the right way, but the h1 tag still contains "Something".
If I check the value of by clicking the button, the console shows me "Something".

Is this a bug or a feature? I would have expected the h1 tag to contain an empty string.

If this is a feature, I would recommand to change that, because this makes it impossible to navigate from /example/something back to /example.

image


My setup:

  • VS 2019
  • ASP.NET Core 3.0
  • Microsoft.AspNetCore.Blazor from NuGet (Version 3.0.0-preview4-19216-03)
  • Default Blazor (ASP.NET Core hosted) Project

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions