-
Notifications
You must be signed in to change notification settings - Fork 10.3k
OnLocationChanged not fired in .NET 8 Preview 7 Blazor Web App #49950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When you set a new uri from the address bar, you lose the state of your app. This is the reason why the LocationChanged event is never triggered and the Id property stay at 0. If you add the following code, you can see, the Id property is now updated when you navigate from the @page "/{*pageRoute}"
@attribute [RenderModeServer(false)]
@inject NavigationManager NavigationManager
@implements IDisposable
@Id.ToString()
<br/>
PageRoute: @PageRoute
<button @onclick="@(() => NavigateTo("/counter1/1"))">Counter 1</button>
<button @onclick="@(() => NavigateTo("/counter1/2"))">Counter 2</button>
<button @onclick="@(() => NavigateTo("/counter1/3"))">Counter 3</button>
@code {
private int Id { get; set; }
[Parameter]
public string? PageRoute { get; set; }
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
NavigationManager.LocationChanged += OnLocationChanged;
}
private async void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
Id++;
await InvokeAsync(StateHasChanged);
}
private void NavigateTo(string nav)
{
NavigationManager.NavigateTo(nav);
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
} |
in .NET 8 Preview 6 the OnLocationChanged get fired using regular a href links like the attached Git Project. The project on https://cms1.l-mediehus.dk/ (Early alfa version) are built on Preview 6 and the links are catched by OnLocationChanged as desired |
It seems to be a bug. But yes, NavigationManager seems to have a problem with We also get the same result with RenderModeWebAssembly. |
Related and will be partially addressed as part of #48766 |
Done in this PR #51279 |
Is there an existing issue for this?
Describe the bug
In the code below (https://github.com/KeldJ/BlazorApp9) navigation to all urls are Catched and should fire OnLocationChanged which increases ID.
@page "/{*pageRoute}"
@Attribute [RenderModeServer(false)]
@Inject NavigationManager NavigationManager
@implements IDisposable
Home
@ID.ToString()
PageRoute: @PageRoute
@code {
}
Expected Behavior
OnLocationChanged should be fired and ID should be increased.
Steps To Reproduce
https://github.com/KeldJ/BlazorApp9
Exceptions (if any)
No response
.NET Version
8.0.100-preview.7.23376.3
Anything else?
No response
The text was updated successfully, but these errors were encountered: