Next.js Discord

Discord Forum

using app router hooks on pages router

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Is it safe to use the "app router" hooks (e.g. usePathname from next/navigation, etc) on a "page router" page? I was expecting it to fail, but seems like it still works (I'm still afraid there might be some weird side effects)

my question is mostly because it would make it easier to migrate those pages to the app router when the time comes

4 Replies

Western paper wasp
The docs for usePathname make a couple specific references to its behavior under the pages router
which implies it’s intentionally supported under pages
they stop short of stating direcltly that usePathname will work under the pages router
but i’d say it’s a reasonably safe bet that it will work as you expect under pages