-
-
Save yuvalkarmi/ab7944b2da693c71cf697db6a47e5b5d to your computer and use it in GitHub Desktop.
@trdbau Oh sorry if I commented something badly. Thank you very much for your feedback!! I appreciate your quick responses so much ^^
@huongnguyenduc NP. Have a good day. Tell us if you find something in the future 😄
I'd used one of the previous (pretty messy and hacky) solutions but that suddenly stopped since upgrading to Next 13. So, I came back to the issue and found this much cleaner solution.
However, I do have an issue that I'm hoping you can help me with. In my _app.ts I am using the router events for my loading animation, like so:
useEffect(() => {
const handleRouteChangeStart = () => {
setIsLoading(true);
};
const handleRouteChangeComplete = () => {
setIsLoading(false);
};
const handleRouteChangeError = () => {
setIsLoading(false);
};
router.events.on("routeChangeStart", handleRouteChangeStart);
router.events.on("routeChangeComplete", handleRouteChangeComplete);
router.events.on("routeChangeError", handleRouteChangeError);
return () => {
router.events.off("routeChangeStart", handleRouteChangeStart);
router.events.off("routeChangeComplete", handleRouteChangeComplete);
router.events.off("routeChangeError", handleRouteChangeError);
};
}, [router.events]);
This seems to take precedence over your event handlers on the component. So,
- browser back button: does NOT display the route change warning
- next/router.back() does NOT display the route change warning
- browser refresh DOES display the warning
I'm pretty new to all this, so please let me know if my loading animation code is not a best practice. Otherwise, what could be a possible solution?
So frickin' glad I came across this. This worked for me on Next 13.2.4.
@huongnguyenduc yah I know bro. I saw that from the start. But in that case, you better commented something like :
Didn't work on my app using new App Router. The version is 13.4.X. Can you help me with that?
. Here we don't know who you are and don't care about it. Be patient and polite. Sure, You can add my telegram and I can help you. Here you go: https://t.me/bautd