letter Q
letter Q

Reputation: 15405

How to save redux state between different URL routes?

I have a react/redux webapp at www.infinity2o.com with multiple routes:

<Route exact={true} path="/profile" component={Profile} />
<Route exact={true} path="/sorting_hat" component={SortingHat} />

The problem I'm having is that my UI color theme is saved into my redux store. But every time my URL route changes like from infinity2o.com/profile to infinity2o.com/sorting_hat my entire state gets reset to null.

Is it possible to keep some of my redux state persistent when switching between routes?

Upvotes: 2

Views: 936

Answers (2)

Vladimir
Vladimir

Reputation: 1

You can save your state in local storage using localStorage.setItem("key", "value"). And set your initial redux state from local storage using localStorage.getItem("key")

Upvotes: 0

nishant
nishant

Reputation: 2606

you can try using redux-persist library

Upvotes: 2

Related Questions