Next.js Discord

Discord Forum

Using router.push outside of React? (with the app router)

Unanswered
Leonberger posted this in #help-forum
Open in Discord
LeonbergerOP
Is it possible to use the navigation router to navigate outside of React?

Previously with the pages router, we could import the Router object directly and call Router.push, but it doesn't seem to be possible now?

4 Replies

Northeast Congo Lion
Check that you're importing
{ useRouter }
from,
'next/navigation';
not from
next/router
LeonbergerOP
i'm specifically looking for a way to use it outside of React - so I can't use the react hooks
Gharial
If you're looking to navigate a user outside the react app/an external resource why not just use window.location as recommended in the docs?

https://nextjs.org/docs/pages/api-reference/functions/use-router#routerpush