Jaisa Ram
Jaisa Ram

Reputation: 1767

Hash history cannot PUSH the same path; a new entry will not be added to the history stack when i am changing state not pathname

I want to change only state not route

<Link to ={{
    pathname: "/questions", 
    state: { 
        by: 'me' 
    }
   }} >
 Me
</Link>

to

 <Link to ={{
        pathname: "/questions", 
        state: { 
            by: 'others' 
        }
       }} >
     others
    </Link>

state is not changing and in console throwing Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack

Upvotes: 0

Views: 2995

Answers (1)

Shubham Khatri
Shubham Khatri

Reputation: 281754

The state value passed through Route navigation is not persisted across browser-refreshes and are also not accounted for in the URL. A better way to handle such scenarios is to make use of query params instead of state. So your url will look like /question?by=me or /question?by=other

You can pass it on like

<Link to ={{
    pathname: "/questions", 
    search: '?by=others'
   }} >
   others
</Link>

and obtain from location like this.props.location.search which you can parse using queryString package or similar

Upvotes: 2

Related Questions