2

This is quite similar to this question here: How to know if react-router can go back to display back button in react app where the ask is regarding determining whether the user can go back in the app.

That answered half the question. The other half: How do I determine whether the user can move forward? I knew this could be possible with access to the history which was possible in v5, but since v6, useHistory doesn't exist anymore.

Any ideas?

Amruth Pillai
  • 1,539
  • 2
  • 13
  • 28

1 Answers1

0

I couldn't find a way to do this through the v6 version of react-router-dom either.

There is an experimental Navigation API property called canGoForward (and canGoback) that I found to work with react-router-dom:

// Defaults to true for browsers that don't support the property
const canGoForward = !window.navigation || window.navigation.canGoForward || window.navigation.canGoForward !== false ? true : false

See the navigation.canGoForward documentation here:
https://developer.mozilla.org/en-US/docs/Web/API/Navigation/canGoForward

It doesn't work on all browsers though, I would be keen to use a more robust solution that utilises the react router.

Loks
  • 224
  • 2
  • 7