Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Option to show a pop confirmation before route change #27146

Closed
AkashGoenka opened this issue Jul 13, 2021 · 2 comments
Closed

Option to show a pop confirmation before route change #27146

AkashGoenka opened this issue Jul 13, 2021 · 2 comments

Comments

@AkashGoenka
Copy link

Describe the feature you'd like to request

I had come across a use case where we had to warn user before they leave the page to another URL or in App Navigation. It would be great to have a feature to perform some logic before route change is initiated.

Describe the solution you'd like

A router event like beforeRouteChange that triggers a callback function where additional business logic can be executed and the routing can be halted/continued on the basis of a boolean returned by the callback.

Another option would be something similar to https://reactrouter.com/core/api/Prompt

Describe alternatives you've considered

I've tried to use window.onbeforeunloadevent, but this does not work in all scenarios (especially in app navigation). It is triggered mostly on closing the tab/browser window.

Another option was a workaround suggested in - #2476 (comment)

@wadehammes
Copy link

You could build something similar using router.events -> https://nextjs.org/docs/api-reference/next/router#routerevents

@AkashGoenka
Copy link
Author

AkashGoenka commented Jul 14, 2021

#2476 (comment) makes use of https://nextjs.org/docs/api-reference/next/router#routerevents. But that seems more like a workaround (not the cleanest way). I want to implement some checks before the next framework starts to unmount the component.

@vercel vercel locked and limited conversation to collaborators Jul 16, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants