Next.js does not redirects with router.push
Unanswered
American black bear posted this in #help-forum
American black bearOP
Hello, I have this simple code:
the fromParam is
the log executes but the router.push does not really push me to anywhere...
case LoginStatus.SUCCESS:
setSessionKey(result.sessionKey);
if (fromParam) {
console.log(fromParam);
router.push(`/${fromParam}`);
return;
}
router.push('/');
return;
the fromParam is
/auth?from=cart
the log executes but the router.push does not really push me to anywhere...
5 Replies
Black Turnstone
Can you share some more code?
Havana
I'm also getting this - and it's incredibly frustrating! I managed to get around it by wrapping redirect inside of a dummy server action, which resulted in it working...
I've literally got a
because my
I've literally got a
magicRedirect
file:'use server';
import { redirect } from "next/navigation"
export const magicRedirect = async (url: string) => {
redirect(url);
}
because my
router.push
is not workingSo a couple things to note,
I'm using NextJS
When I do router.push, I can see the URL in the topbar change and the navigation bar update (although I believe this is dependant on the url) but the actual page content doesn't go anywhere, I can confirm this also happens on both dev and when I do
router.push
works everywhere but this file.I'm using NextJS
"15.0.1"
I tried having upgraded to the latest version and no dice.When I do router.push, I can see the URL in the topbar change and the navigation bar update (although I believe this is dependant on the url) but the actual page content doesn't go anywhere, I can confirm this also happens on both dev and when I do
build & start
Doing
window.href.
also works, but I need the context to be persisted between the page transitions and window.href refreshes the state of the contexts.Havana
I found out what was causing this, there's a realtime segment to my app, which was calling a server action causing a race condition