Next.js Discord

Discord Forum

Nextjs 15 events after router.push()

Unanswered
Giant Angora posted this in #help-forum
Open in Discord
Giant AngoraOP
Hi guys, I'm trying to do some actions after
router push(), for example.

async function onClick(){
router.push() // i want a way to wait for this to finish, then execute the rest of the code.
await someAsyncCode()
}

4 Replies

@Giant Angora Hi guys, I'm trying to do some actions after `router push()`, for example. async function onClick(){ router.push() // i want a way to wait for this to finish, then execute the rest of the code. await someAsyncCode() }
There's currently no official solution from the Next.js team for making router.push() awaitable in the App Router, or wait for it to finish.

You can perhaps use little complex methods like working with usePathname, but you can just execute code on redirected page if required
Can I ask why are you trying to achieve this? Maybe the solution you need is simpler than that
Yes, this is also a xy question