T
TanStack8mo ago
like-gold

Run callback when someone exit the page

Hey, Is there a way to run callback when someone leave the page?
4 Replies
mere-teal
mere-teal8mo ago
leave where to?
like-gold
like-goldOP8mo 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?
mere-teal
mere-teal8mo 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
like-gold
like-goldOP8mo ago
thank you!

Did you find this page helpful?