Next.js Discord

Discord Forum

Next.js does not redirects with router.push

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
Hello, I have this simple code:
            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 magicRedirect file:
'use server';
import { redirect } from "next/navigation"

export const magicRedirect = async (url: string) => {
    redirect(url);
}


because my router.push is not working
So a couple things to note, 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