See list of history through react-router props
Asked Answered
J

1

7

I currently have a button that onClicks to history.goBack but I want it to direct the user to another path if there isn't a previous page (in the case the user visits the page directly by typing in the URL in the URL bar instead of clicking within the site to get there). When I checked out this.props.history there isn't an object containing the history of pages visited or a boolean that tells me if there is a page for history.goBack to work on. How do I check that? Looking at the docs for history library, there is suppose to be an entries property but this somehow didn't make it into react-router.

Jinnyjinrikisha answered 8/1, 2017 at 1:59 Comment(0)
L
0

You can use go() property to move further back. Eg. go(-1) will be equivalent of goBack() and go(1) will be equivalent of goForward(). I don't think there is a way to list all the paths on the stack, but you could allways implement history that you can push to and control.

Latarsha answered 21/1, 2021 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.