Preventing Navigation on Back Browser Click When Modal is Open #52195
Unanswered
AnasBoulmane
asked this question in
App Router
Replies: 2 comments
-
Next has documentation on how to implement a modal using parallel routes. However, I found that path too complex. I chose to display the modal by adding a Hope this helps :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Any update guys? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Next.js Community,
I've been working with Next.js and have encountered a specific scenario that I'm struggling to find a solution for. I have a modal in my application, and I want to prevent navigation when the back button in the browser is clicked while the modal is open.
Currently, when the modal is open and the user clicks the back button in the browser, the application navigates to the previous page. However, I want the back button click to only close the modal and not navigate away from the current page Achieving Mobile Native-Like Behavior.
I've searched through the issues and discussions here but couldn't find a specific thread that directly addresses this issue. I'm wondering if anyone else has encountered this scenario and how they've handled it.
Here's a brief overview of my current setup:
1- I'm using Next.js App router.
2- The modal is implemented using radix-ui/react-dialog.
the only solution I can think of is using routerbeforepopstate but my app is based on the App router
Has anyone else faced this issue? Any guidance or suggestions would be greatly appreciated. Thank you in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions