-
Notifications
You must be signed in to change notification settings - Fork 51
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
Use commands.prevent() #314
Comments
Confirmed. The documentation on custom route actions does not match the actual implementation. I am not sure which of the two is the intended behavior, but it's definitely a bug. As a workaround you could try using the |
Thanks!! |
Any timeline on updating the commands in the action object with a prevent method ? |
This throws an error in the console... |
I don't know where I have found it, but this is how i use it: onBeforeLeave(location, commands, router) {
if (this._unsavedChanges) {
const dialog = document.createElement('x-dialog');
dialog.title = 'Warning!';
dialog.template = html`Unsaved changes. Save changes first!`;
this.renderRoot.appendChild(dialog);
return commands.prevent()
}
} Notice, that I check my navigation before leaving a component rather than before entering a new one. Hope it helps! |
We also have the use case where we want to prevent routing when the user decides from a discard changes dialog. Actions are always executed, so when we prevent routing in an onBeforeLeave the action which might have side effects are already executed. Workarounds become very fuzzy and preventing router actions etc. makes it clear. We now show a dialog in a router action to prevent the action, remember the decision of the user and act on this on the onBeforeLeave with a comment.prevent(). But as mentioned, this becomes fuzzy. Any plans to:
Related: |
Hi!,
How can I execute commands.prevent() in my action?
I don't see the method in commands object.
Thanks!
The text was updated successfully, but these errors were encountered: