Skip to content

history.location.key equivalent in v6? -- How to check if previous item in history stack exists in react router v6? #9788

Discussion options

You must be logged in to vote

In v6, you can inspect the location object returned by the useLocation hook for this use case. When the history stack is empty, the location.key will have the value "default".

const doesAnyHistoryEntryExist = location.key !== "default";

Ref: history library docs

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@cliffordfajardo
Comment options

Answer selected by cliffordfajardo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants