Lost persist in Dynamic routes
See original GitHub issueI have integrated your library with redux and redux-persist, everything works fine and persistent data is found when loading and reloading the page, but when reloading on dynamic routes the persistent data is lost. For example, the loading and reloading on “/home” everything works fine, but when “/posts/[id]” persistent data is lost
redux/store.js
import { createStore, compose, applyMiddleware, combineReducers } from 'redux'
import { persistStore } from 'redux-persist'
import { createWrapper } from "next-redux-wrapper";
import thunk from 'redux-thunk'
import { reducers } from 'redux/reducers/index'
const makeStore = () => {
let store;
let persistor;
if (typeof window !== 'undefined') {
const { persistCombineReducers } = require('redux-persist');
const storage = require('redux-persist/es/storage').default;
const config = {
key: 'root',
blacklist: ['search', 'database'],
storage,
}
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// const composeEnhancers = compose;
store = createStore(persistCombineReducers(config, reducers), composeEnhancers(
applyMiddleware(thunk)
));
persistor = persistStore(store)
store.__persistor = persistor
}
else {
const composeEnhancers = compose;
store = createStore(combineReducers(reducers), composeEnhancers(
applyMiddleware(thunk)
));
store.__persistor = null
}
return store
}
export const wrapper = createWrapper(makeStore);
_app.js
import { Provider, useStore } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
import { wrapper } from 'redux/store'
function MyApp(props) {
const { Component, pageProps } = props
const store = useStore((state) => state);
return (
<React.Fragment>
<Provider store={store}>
<PersistGate persistor={store.__persistor} loading={null}>
<Component {...pageProps} />
</PersistGate>
</Provider>
</React.Fragment>
);
}
export default wrapper.withRedux(MyApp);
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Dynamic routing gives an error when updating the page Next.js
As I understand it, when updating a page from its route, the id is lost, which is why fetch cannot be executed enter...
Read more >Page state is not reset for navigating between dynamic routes
Bug report Describe the bug The page state is not reset for navigation between dynamic routes that served by the same source component....
Read more >The running dynamic route configuration is truncated ... - AskF5
The running dynamic route configuration on your BIG-IP system is truncated and dynamic routing may not function as expected. This issue occurs ...
Read more >Routing in Next.js – How to Set Up Dynamic Routing with Pre ...
In this tutorial, you'll learn how to set up dynamic routing in Next.js. ... you out on this specific fact that getStaticPaths() is...
Read more >Shallow Routing - Next.js
Shallow routing allows you to change the URL without running data fetching methods again, that includes getServerSideProps , getStaticProps , and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you just share it?
I have found the answer, but thanks for the help