-
Notifications
You must be signed in to change notification settings - Fork 249
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
Hook not firing on first page unload #179
Comments
Yep, I see what's the problem. When I started working on Navigo SSR wasn't a thing :) So, indeed because of the SSR the const actualHandler = function () {
console.log('actual handler');
}
const cleanUp = function (handler) {
return () => {
// cleaning up, fade out previous page etc
handler();
}
}
router.on('/some/url', cleanUp(actualHandler)); |
hi again, Thanks for the quick reply! In the end I did get my hack with the
In any case, not sure if I misunderstood your reply or if it isn't applicable to my specific case: a route does not have access to anything but itself and the router, so it cannot clean up after the previous route on navigate. As such, it doesn't matter whether A rough timeline of what I'm trying to achieve would be:
|
There is a new version 8.0.0 which has a solution of the problem here. It is an option of the navigate method. router.hooks({
leave(match) {
console.log("leaving ", match);
},
});
router
.on("/about", (match) => {
render("About");
})
.on("/products", (match) => {
render("Products");
})
.on("/login", (match) => {
render("Login");
})
.on(() => {
render("Home");
});
router.navigate("/login", { silent: true }); The P.S. |
Hello, @krasimir!
Thank you for this nice library, it's very handy to have a vanilla js router.
On my current project, I skip resolving the routes on page load since the server already serves the correct and fully formed page. However, when the user navigates away from the page, the
leave
hook does not fire (which is unfortunate since I rely on it to do some clean up before the page transition). Is this expected behaviour?A few snippets of relevant code:
As you see I do try a somewhat hack-y solution by setting _lastRouteResolved, but it hasn't worked. Any ideas on how to solve this?
Thanks again!
The text was updated successfully, but these errors were encountered: