I have two react components let say A and B. When A is shown on the page, user changes something on that page which cause some states changed inside A. Then user click a button which navigate to B by router.push('/b'). Then user click a back a back button and navigate the page to A which is done by router.goBack(). Now the current URL is A but the previously updated states are gone. How can I maintain the state when user go back to A? without using redux or localstorage as I want to do this with react-router-dom directly.
Asked
Active
Viewed 378 times
0
-
Did you. checked this https://stackoverflow.com/questions/50130622/react-router-v4-previous-state-component – Learner Feb 18 '21 at 12:25
-
Check this one also https://stackoverflow.com/questions/41466055/how-do-i-pass-state-through-react-router#answer-41499419 – Learner Feb 18 '21 at 12:27
-
You need to store your state somewhere. – MinusFour Feb 18 '21 at 12:28
-
use useContext hook – Sayog Feb 18 '21 at 12:42
-
@DILEEPTHOMAS yes I have checked this but in this solution they are using localstorage. All I want to know is there some way which i can achive this directly from react-router-dom? l – Muhammad Jaffar Raza Dar Feb 18 '21 at 13:56
-
you can put it in that way react router state you can do but not recommended as a good way, in the second comment i have posted it has all the ways do check it – Learner Feb 18 '21 at 14:21