Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send custom data in react-router goBack method like push and replace methods?

I am using react-router-dom v4 and able to send custom data to the new screen using push(path, state) and replace(path, state) methods in "props.history.location"

I want to send the data back to the previous screen but could not achieve using go(n) or goBack() or goForward().

How can I solve the scenario when I need to send data back to the previous screen?

like image 627
Ram Babu Avatar asked Mar 02 '26 17:03

Ram Babu


1 Answers

I don't think you can pass params directly when going back.

However, it is possible to accomplish this in different ways.

You can implement redux and have an action/reducer for this. (requires some boilerplate work)

Or easier, you can store your data in localstorage and read it in the page. Be careful to use async for localstorage when reading data.

These two should work.

like image 68
rei koleci Avatar answered Mar 04 '26 05:03

rei koleci