T
TanStack10mo ago
optimistic-gold

Run callback when someone exit the page

Hey, Is there a way to run callback when someone leave the page?
4 Replies
other-emerald
other-emerald10mo ago
leave where to?
optimistic-gold
optimistic-goldOP10mo ago
For example User is on /home page, then clicks on Link which redirect him to /settings page and after some time user click on the browers back button and in this time i wanna run callback So basically, when someone clicks the browers native back button i wanna run the callback, can tanstack router handle this?
other-emerald
other-emerald10mo ago
there are multiple ways. you can subscribe to router events or history events you can also have a look at the blocker if you want to prevent the user leaving
optimistic-gold
optimistic-goldOP10mo ago
thank you!

Did you find this page helpful?