Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  67] [ 1]  / answers: 1 / hits: 82010  / 6 Years ago, wed, december 5, 2018, 12:00:00

My react router has state isActive(boolean) value. When I use the Link component to redirect to different route I can update the state as follows and its working fine:-



<Link to={{
pathname: my-home-page,
search: '?query=abc',
state: { isActive: true }
}}>Go to Home</Link>


Also when I use history.push state is updating correctly bu using below code:-



history.push({
pathname: '/template',
search: '?query=abc',
state: {
isActive: true
}
});


However when I am using history.replace in javascript I am not able to update the state. I am trying the below code however its not working.



history.replace({ pathname: 'home', search: '?query=abc', isActive: true});


Anyone knows what I am doing wrong? Why my state is not updating while redirecting with history.replace


More From » reactjs

 Answers
197

What version of the router is it?
In History API, and when I've used it, the first parameter is the pathname (without object, just the string), and the second parameter is the state.


[#52978] Friday, November 30, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rayvenc

Total Points: 666
Total Questions: 125
Total Answers: 99

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
;