Allow navigation without triggering OnParametersSet
See original GitHub issueThis 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:
- Created 3 years ago
- Reactions:2
- Comments:15 (15 by maintainers)
@danroth27 What public info can we give about internal Blazor usage?
@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 theNavigationManager.Uri
in sync when I do areplaceState
, but not triggering events normally associated with changing thatUri
. In the case of canceling, my browser URL andUri
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!