Open jiwoniverse opened 1 year ago
Hello, thank you for your feedback!
If you're wondering why the modal shown when trying to refresh the page is different from the one you see when clicking a Link
, that is because it is not possible to show a custom modal for the beforeunload
events, due to browser security reasons.
If you're wondering why no browser-native modal is shown at all, then, to be honest, I'm not sure why the refresh prevention would not work as expected. Especially if you're using the exact same hook I provided in the README, which seems to be the case. Maybe the event listener you add in a useEffect
in file app/community/write/page.tsx
somehow gets in the way? Even if it doesn't, you don't really have to add the beforeunload
event listener yourself, as the useBeforeUnload
hook does that for you and it's already used appropriately inside the useLeaveConfirm
hook, so I suggest you just remove it.
If that doesn't help, please get back to me and specify which browser do you encounter this issue with, I'll try to look into it.
As for the browser back button: that's a bit of an oversight on my end and I have already confirmed this issue😅. I'm currently too busy with other stuff, but I will try to fix this as soon as I have enough free time!
Hello, thank you for your feedback! If you're wondering why the modal shown when trying to refresh the page is different from the one you see when clicking a
Link
, that is because it is not possible to show a custom modal for thebeforeunload
events, due to browser security reasons. If you're wondering why no browser-native modal is shown at all, then, to be honest, I'm not sure why the refresh prevention would not work as expected. Especially if you're using the exact same hook I provided in the README, which seems to be the case. Maybe the event listener you add in auseEffect
in fileapp/community/write/page.tsx
somehow gets in the way? Even if it doesn't, you don't really have to add thebeforeunload
event listener yourself, as theuseBeforeUnload
hook does that for you and it's already used appropriately inside theuseLeaveConfirm
hook, so I suggest you just remove it. If that doesn't help, please get back to me and specify which browser do you encounter this issue with, I'll try to look into it. As for the browser back button: that's a bit of an oversight on my end and I have already confirmed this issue😅. I'm currently too busy with other stuff, but I will try to fix this as soon as I have enough free time!
Thank you so much for your comment!
First of all, I'm using the Chrome browser. And when I checked again, the browser default refresh prevention works, so I'm sorry that I talked about this part.
The event listener in the file app/community/write/page.tsx
works the same, with or without. I think I put it in while fixing codes.
The problem is the case of browser back button, and I understand the issue that you checked!
Lastly, I want to say thank you again for leaving a comment. I hope you're always full of luck! ☘️
Hi! I am currently studying front-end development. I used your library during the project, and I opened the issue because I had a question. (The project is using Next.js 13, and App router.)
After install your nextjs-router-events library, and I want to prevent by pop-up a modal window when a user leaves the write page.
The modal pops up well when I try to leave via
<Link>
in navigation bar, but the problem is that it doesn't pop up normally when leaves using browser-native navigation methods(refresh or backspace).My current code is as follows.
I'm sorry I couldn't summarize the problem and brought you soooo long codes. This is my first Next.js project, so there are many things I don't know yet, and this summary was my best shot...😂
You can also see the whole code below. https://github.com/Savers-Save-Earth/Savers/tree/163-fix-community-page
Thank you very much for the wonderful library. ✨ Have a nice day!