T
TanStack3y ago
extended-salmon

How to check if it's possible to go back

I'm aware you can go back with history.back(), but I would like to know if I can go back in the first place because I want to close my app when I can't go back anymore with gestures for example, is there a way to check if router can go back ?
1 Reply
multiple-amethyst
multiple-amethyst3y ago
I actually don't think there's a built-in way to do this. You can pretty easily implement it yourself though by using a usePrevious hook, setting and pulling the path from local storage, setting it to null by default. Here's a reliable hook I use for that: https://usehooks.com/useprevious
usePrevious React Hook – useHooks
Track the previous value of a variable with usePrevious.

Did you find this page helpful?