When the user refreshes the page, the first LOCATION_CHANGE will light up because you are synchronizing the history with the repository. However, it only synchronizes the history and does not redirect the user to anywhere else.
The only thing that matters is the second LOCATION_CHANGE , which should happen after persistStore() . The good news: persistStore() has a callback.
const store = ... // persist store persistStore(store, options, () => { const states = store.getState(); // if authenticated, do nothing, // if not, redirect to login page if (!states.auth.isAuthenticated) { // redirect to login page } }); render(...);
Hope this helps solve your problem.
haipham23
source share