Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass object as props to previous react component when navigating back with browser back button (react, react router )

I am using react-router for navigation in my app.

To pass some data from current component to other component while navigating using Link we use:

this.props.history.push('/other-page', { id: 7, color: 'green', .... }))

How can I pass data(object) to the previous component from current component when browser back button is clicked ?

PS: I saw some solutions where it is suggested to pass some data with query string but I don't want to use it because I have to pass a big object with many properties.

So it possible with react-router ? Our I would have do that with state in some outer component or use Redux store for shared data ?

Thanks.

like image 309
AMIT KUMAR Avatar asked Jul 02 '26 14:07

AMIT KUMAR


1 Answers

It will be better to use some storage like reducer if some data could be used in different components. It is much better, then pass data through query params or callbacks. You can use react-redux or migrate from class components to functional and use useReducer hook.

If you need some example, please let me know.

like image 92
Andrii Golubenko Avatar answered Jul 05 '26 05:07

Andrii Golubenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!