Everything I've read points me to using NavigationManager.LocationChanged event, however that does not detect when only the query string changes. Therefore, nothing fires.
I've tried what is suggested here and that does not do what I am looking for.
I need my component to rerender everytime the query parameters in the current route changes. Has anyone been able to do this?
UPDATE:
Here is my code example:
@page "/accounts"@if (Accounts != null){<table><tbody> @foreach (var account in Accounts) {<tr><td><NavLink href="/accounts/?accountId={account.AccountId}">@Account.Name</NavLink></td></tr> }</tbody></table>}@if (Account != null){<div><h2>@Account.Name</h2></div>}@implements IDisposable@inject NavigationManger NavManager@inject AccountService AccountService@code { protected Guid Id { get; set; } = Guid.NewGid(); protected Guid AccountId { get; set; } = Guid.Empty; protected List<AccountModel> Accounts { get; set; } protected AccountModel Account { get; set; } protected override void OnInitialized() { NavManager.LocationChanged += LocationChanged; } protected async override Task OnParametersSetAsync() { if (AccountId != Guid.Empty) { Account = await AccountService.GetAsync(AccountId); } else { Accounts = await AccountService.GetAllAsync(); } StateHasChanged(); } void LocationChanged(object sender, LocationChangedEventArgs e) { Id = Guid.NewGuid(); StateHasChanged(); } void IDisposable.Dispose() { NavManager.LocationChanged -= LocationChanged; }}The problem here is LocationChanged(object, LocationChangedEventArgs) does not fire when only the query parameters change. Which makes sense, the route is the same /accounts.
Bascically I have one page to show a list of Accounts and view a single account. I want the route to be /accounts when view the list and '/accounts?accountId=someAccountId' to be the route when im viewing one. Using standard NavLink component does not trigger a rerender of the component and neither does the LocationChanged event. Not even with setting a new Id value. Seeing as to how StateHasChanged only rerenders the component if a value has changed.