-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Describe the problem
beforeNavigate((navigation) => {
if (!confirm('Hello World')) navigation.cancel();
});This code is sufficient to trigger the browser-generated dialog.
Leave site? Changes that you made may not be saved. — Google Chrome
This can be reproduced by:
- Calling the
beforeNavigatein the root page component. - Starting a development server and navigating to the
/page. - Interact with the page and then attempt to close the tab (window).
This can confuse users, since the provided "Hello World" message is not used.
Instead, the browser provided generic dialog is shown. (which is intended)
Describe the proposed solution
In the beforeNavigate documentation:
- State that if
navigation.willUnloadistrue, custom alerts cannot be shown. - State the reason why the browser default dialog is shown in the following usage.
beforeNavigate((navigation) => {
if (!confirm('Hello World')) navigation.cancel();
});- Provide a way to reproduce the browser default behavior - such as calling the
preventDefault()method in the beforeunload event's object.
Alternatives considered
I wasn't able to create a docs PR because I was uncertain about the way this works.
Is is because
- When the
navigation.willUnloadistrue, - The
beforeunloadevent handler is used with apreventDefault()?
addEventListener("beforeunload", (event) => {});Importance
nice to have
Additional Information
No response
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation