dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Expose location changing event for NavigationManger #14962

Closed Postlagerkarte closed 2 years ago

Postlagerkarte commented 5 years ago

The NavigationManager exposes

LocationChanged | An event that fires when the navigation location has changed.

but it does not expose a LocationChangingevent.

Such an event that occurs before navigation takes place is very useful because it allows the previous view to prepare for its deactivation, for example, to display a warning, cancel navigation or silently save changes.

Can you provide such a feature or is there already another way to achieve the above?

ShaunCurtis commented 2 years ago

Daniel,

Brilliant - I'm happy to have been proved wrong! I've just run some quick tests and it looks to cover all the bases. Having had a lot of people looking at it, I didn't think it was possible without upsetting the Blazor JS code.

I'm planning to do more in-depth testing tomorrow and incorporate it into a demo project.

Can I include this in my latest Blazor Edit Form code release? If so what copyright header notice do you want?

Liero commented 2 years ago

@ShaunCurtis: you can use or modify the code freely, no need for any credits. If you want, you can find me on linked-in. I'm not sure this works all the time, so be careful. I just wrote it today.

ShaunCurtis commented 2 years ago

Daniel,

Did you test this in WASM? It works great in Server, but I'm having issues in WASM.

pranavkm commented 2 years ago

Given there are some challenges to supporting this feature as-is across different flavors of Blazor, our team is trying trying to gauge if a more limited solution would suffice here based on this feature spec: https://github.com/dotnet/aspnetcore/issues/40149. Could you look at it and give us feedback? Thanks!