How do I know if I can go backwards/forwards in React Router

Viewed 68

How can I test to see if I can go backwards or forwards in React Router v5?

I see nothing in the history object that can tell me where I am currently/what the the current index is:

action: "PUSH"
block: ƒ block(prompt)
createHref: ƒ createHref(location)
go: ƒ go(n)
goBack: ƒ goBack()
goForward: ƒ goForward()
length: 8
listen: ƒ listen(listener)
location: {pathname: "/", search: "", hash: "", state: {…}, key: "6x0l42"}
push: ƒ push(path, state)
replace: ƒ replace(path, state)

I tried using createMemoryHistory(), as it's supposed to give me history.index, but it doesn't appear to work, giving me the exact same entries as above.

const history = createMemoryHistory()
return (
  <Router history={history}>
  ...
  </Router>
)
0 Answers
Related