-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next 7 - Router.push() does`t work as expected #5264
Comments
Can you create a minimal github repository? That way I can add tests for it if there is indeed a problem, but I suspect there's something else going on. |
I will need some time to prepare repository, but for now, can you tell in what situations Route can be cancelled ? |
same problem all pages where i use import css not working. |
This is probably the same bug as here: #5203 |
And this is also the same: vercel/next-plugins#282 |
I found comments in Router error: this.abortComponentLoad(as); // If the url change is only related to a hash change
// We should not proceed. We should only change the state. So for me solution was to use window.location: if (Router.router.pathname === '/search') {
Router.push({ pathname: '/search', query: { ...Router.router.query, ...newQueryParams } })
} else {
window.location.replace(`/search?page=${newQueryParams.page}&address=${newQueryParams.address}`);
} |
This doesn’t sound like the correct solution. Could you provide a minimal reproduction? |
Same here. I have simple component that redirects on mount (simple page redirect), router fires events about navigation start, but it never completes. |
@timneutkens In vercel/next-plugins#282 @standy linked this as his minimal reproduction: |
Not working |
Workaround for bug caused by the chunks having a deferred module dependency on the style chunk, but the style chunk is never loaded, so the new chunk never executes. If you depend on a css file from the _app.js file, then the style chunk will always be available and the new route executes once it's loaded. see vercel/next.js#5264,
FWIW, I randomly encountered this issue and importing a random .css file in _app.js fixed it |
It's bitten me too, that was a good 2 hours of pulling my hair out. @msand workaround fixed it though so a massive thanks. |
After following steps, it is still not working. could you please let me know the workaround for the same ? |
@msand you saved my life. Thank you. |
I was having a problem with redirection using useEffect(() => {
if (authResult) {
Router.push({ pathname: '/workspaces' }, '/workspaces')
}
}, [authResult]) Now I have: useEffect(() => {
if (authResult) {
Router.events.on('routeChangeStart', url => {
window.location.href = url
})
Router.push({ pathname: '/workspaces' }, '/workspaces')
}
}, [authResult, Router]) It doesn't smell good but hopefully helps someone. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Next 7 - Router.push() does`t work.
To Reproduce
I have a search handler that should redirect to '/search' page from main page. But nothing happens.
routeChangeError throws Route cancelled. But on Next 6.1.2. everything works fine.
Also if I go to the link http://localhost:8080/search directly it works as expected, seems like a problem with client side routing. Using HOC withRouter gives the same results.
Expected behavior
Expected to work the same as in Next 6.1.2
System information
The text was updated successfully, but these errors were encountered: