Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Lifecycle events #28527

Closed
MariovanZeist opened this issue Dec 8, 2020 · 4 comments
Closed

Navigation Lifecycle events #28527

MariovanZeist opened this issue Dec 8, 2020 · 4 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description
Milestone

Comments

@MariovanZeist
Copy link
Contributor

Summary

We would like to implement a Navigation lifecycle event, that should be called BEFORE navigation is performed, with the ability to cancel that navigation.

Motivation and goals

The main reason for this lifecycle event is that currently, we have no way of canceling a navigation event, which is useful if for example the user has made some changes in a form, but navigates away from that page before those changes could be stored.

For reference, some work has already been done in #24417 ,
One of the problems we face in that PR is that we want the event to be asynchronous. So using an EventHandler is out of the question. Also the location on where to place this event (Navigationmanager, Router) is under discussion.

In scope

Canceling navigation Lifecycle events.

Out of scope

Risks / unknowns

The performance issue I can think of is that every navigation event (clicking a href for example) in Serverside Blazor would incur an additional client/server callback, even when no one is listening. This can be mitigated by only calling the lifecycle event when a listener is actually supplied. (This has been addressed in the PR)

Examples

//Set to true when Data has been modified that has not yet been stored
bool PageIsDirty { get; set;}

//Function that is called when a navigation event occurs (returns true when navigation should be canceled)
ValueTask<bool> LocationChanging(string uri, NavigationOptions options)
{
  if (PageIsDirty)
  {
    var result = await ShowDialog($"Changes have not been saved. Are you sure you want to navigate to:{uri}", Buttons.YesNo);
    return result != Button.Yes; 
  }
  return false;
}
@MariovanZeist MariovanZeist added the design-proposal This issue represents a design proposal for a different issue, linked in the description label Dec 8, 2020
@MariovanZeist
Copy link
Contributor Author

@captainsafia I hope you still want to co-author this design proposal with me. Feel free to modify it.

@ShaunCurtis
Copy link

ShaunCurtis commented Mar 18, 2021

Hi,

I know I'm one of many (countless many), but my approach to this has changed since I first registered an interest a year ago. At that point i thought this was a must, but as my "knowledge" increased I realised there are more than x ways to skin a cat (x++ to play on a pun). I no longer use my "alternative" router to get around the problem. See Inline Dialog for my most recent solution.

So maybe the solution is "Education" rather than what is proposed. Would help in any shape or form if asked - I'm bored silly in COVID lockdown in the UK.

@ghost
Copy link

ghost commented Apr 15, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia
Copy link
Member

Thanks for opening this issue, @MariovanZeist! Closing this in favor of #14962 until there is capacity to flesh out the design for this. We'll use this issue and the PR as a basis for that then.

@ghost ghost locked as resolved and limited conversation to collaborators May 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description
Projects
None yet
Development

No branches or pull requests

5 participants