Closed hacktisch closed 4 years ago
It's a problem with unsync of initialState and actual location. So you always have to set a proper initialState, or else it'll redirect you during the next request. In my case it was even a backend request.
@hacktisch You can try my fork
npm i github:DZakh-forks/connected-next-router#a5c507b3e41091f2a6f53abee33be2fefd1b3355
And add the clientSideAutosync
flag to the ConnectedRouter
.
It's not an ideal solution but it works for me.
And if you do a redirect inside of useEffect, you need to wrap it in:
Router.ready(() => {
setTimeout(() => {
// ...
});
});
Meh...
@hacktisch This should be fixed in V4. Please reopen this issue if you notice it still happens
There is a bit of code in ConnectedRouter.js that checks for "locationMismatch" on store changes. This mismatch apparently also happens when a request contains query parameters. Maybe it doesn't happen in every use case of connected-next-router, so I'll describe my setup:
I have one Next.js page that catches all routes ([[...slug]].js) It uses getStaticPaths for a list of default paths to make static pages, and has fallback: true to ensure catching all routes.
ConnectedRouter is wrapper around the Component in _app.js