Skip to content

Reimplement warning prompt with wouter#874

Merged
loichuder merged 1 commit into
mainfrom
warning-prompt
Jun 30, 2026
Merged

Reimplement warning prompt with wouter#874
loichuder merged 1 commit into
mainfrom
warning-prompt

Conversation

@loichuder

Copy link
Copy Markdown
Member

#873 (comment)

I struggled to reach the solution but in the end it is not so bad.

The only difference is that the hook needs to be implemented at the Router level since it needs to intercept any call to navigate. It results in an additional condition to check the location compared to the react-router implementation.

We can work on the session storage next and perhaps remove the internal navigation warning.

Comment thread src/edition/hooks.ts
Comment on lines +21 to +25
useEventListener(window, 'beforeunload', (event: BeforeUnloadEvent) => {
if (displayWarning) {
event.preventDefault();
}
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for external navigation so same as https://github.com/ewoks-kit/ewoksweb/pull/789/changes

Comment thread src/edition/hooks.ts
Comment on lines +27 to +43
return [
location,
(newLocation, options) => {
if (!displayWarning) {
setLocation(newLocation, options);
return;
}
// eslint-disable-next-line no-alert
const perfomNavigation = window.confirm(
'There are unsaved changes that will be lost when navigating to another page. Do you want to continue?',
);

if (perfomNavigation) {
setLocation(newLocation, options);
}
},
];

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For inner navigation

Inspired by molefrog/wouter#39 but without the specific context since on our case, the workflow store already acts as the context

@loichuder loichuder force-pushed the migrate-to-wouter branch 3 times, most recently from bf3c82d to 3bc7ff1 Compare June 30, 2026 07:36
Base automatically changed from migrate-to-wouter to main June 30, 2026 07:44
@loichuder loichuder merged commit 8bec00d into main Jun 30, 2026
2 checks passed
@loichuder loichuder deleted the warning-prompt branch June 30, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants