Open JacoJordaan opened 4 years ago
@JacoJordaan , I am new to Blazor but NavigationManager.NavigateTo() method along with checking for your object state in code should help.
I suspect what @JacoJordaan is after is a browser dialog warning the user they are about to navigate away from a page with unsaved data?
In Blazor there are multiple ways the user can navigate away. They might click a link or button that directly navigates, or they might click a link or button that runs some code which uses NavigationManager
.
The former case is the hard one to solve, because none of your code runs prior to that navigation. The latter case is solvable because (as @Chicagoan2016 notes) you can check the state of the domain object and choose whether to navigate or not.
I don't know an answer to the first case: direct link navigation.
If anyone has figured it out, they are almost certainly on the Blazor gitter.im channel. Someone like @chrissainty, who's got an extensive Blazor add-on framework called Blazored might have solved this already.
Thanks for all the feedback.
The major issue is the case for a link that directly navigates or even a browser that are closed without saving of object. I will check out the resources specified.
Hey, sorry I've only just seen this.
So as far as I'm aware, right now there is nothing in the framework that is going to help you deal with this. We could really use a LocationChanging
event or something similar that gets called prior to navigation happening.
You may be able to wire up something yourself with some JS interop, the beforeunload might be a good place to start.
Question A common scenario with csla objects is to have a button where a user can save object to persist the data. Coming from Wpf it is quite easy to prevent user from navigating of page until he/she has confirmed saving or discarding of changes.
With Blazor it does not look like there is an easy way to have the same functionality in place especially with navigation to different place or closing of browser.
I know this is not strictly CSLA related but I just want to find out how others handle scenarios like these?
Version and Platform CSLA version: 5.1.000 OS: Windows, Linux Platform: Blazor Server/Client