question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow navigation without triggering OnParametersSet

See original GitHub issue

This was requested by @zbecknell following a different comment:


We’re coming up to about a year of developing a Blazor app for a new project with a small team, and it’s amazing! Thanks to this, we’ve encountered a good number of scenarios with a variety of challenges. As an example scenario I have a page with the following route:

/account/{accountId}

When on this page, there is the possibility of navigating from say /account/1 to /account/2 via NavigationManager – this causes OnParametersSet to trigger, but NOT OnInitialized since the page is already loaded, so we need to rely on OnParametersSet to know when to reload our page state for a different account.

We want to assume that OnParametersSet triggering really means that a page parameter has changed, otherwise we’d need to keep track of each parameter’s before and after state and manually allow the data to reload.

This is why I want to bypass the LocationChanged event, BUT I still need my NavigationManager.Uri to stay synced with the actual browser’s URL, otherwise I’d need to use JsInterop to retrieve the actual URL, which necessarily needs to be async, which introduces yet more timing complexity. (I can’t use the sync JsInterop because I dual-host client/server Blazor.)

I’m already using interop for my current solution, but it has a bug due to the Uri not being in sync. I’m probably going to solve this in the interim by keeping track of my own Uri variable instead of relying on NavigationManager.


All that being said, this is why another proposal of mine was just letting me set the Uri for NavigationManager programmatically to manually keep it in sync, but I get why that would be likely to cause confusion, and thus isn’t an acceptable solution.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveSandersonMScommented, Sep 10, 2020

One question I’ve been meaning to ask: is there any dogfooding planned/announced for Blazor yet?

@danroth27 What public info can we give about internal Blazor usage?

1reaction
zbecknellcommented, Sep 10, 2020

@MariovanZeist It’s not that the Uri is unknown at the point of it changing – I instigated the change so I know it at that point – it’s about keeping the NavigationManager.Uri in sync when I do a replaceState, but not triggering events normally associated with changing that Uri. In the case of canceling, my browser URL and Uri would not have the desired changes I want.

I think a manual solution is going to work for me for now. And heck, maybe there’s some elegant solution to the OnParametersSet problem that I’m missing, and will hopefully discover over time. Looking forward to seeing how this all evolves. Even being on the bleeding edge it’s been a great development experience!

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Blazor, why does invoking NavigationManager. ...
NavigationManager.NavigateTo(string) is only invoking the one time. Here is your issue (you are very close!): [Parameter] public int?
Read more >
ASP.NET Core Blazor routing and navigation
This article explains how to manage Blazor app request routing and how to use the NavLink component to create navigation links.
Read more >
ASP.NET Core Razor component lifecycle
Learn about the ASP.NET Core Razor component lifecycle and how to use lifecycle events.
Read more >
Bug? AutoComplete inside EditForm - infinite loop with ...
Hi Ben,. The infinite loop comes from updating the Model field - it triggers the OnParametersSet, where the model gets updated again, and...
Read more >
Component Lifecycle in Blazor Server .NET 5
Server triggered. OnParametersSet(), Respond to property changes. Called after OnInitializedAsync() and whenever a property with attribute [Parameter] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found