#useRouter next/navigation how to do shallow routing?

9 messages · Page 1 of 1 (latest)

near oyster
#

I am trying to use useRouter from next/navigation within page router to do incremental migration. however, I am struggling to do shallow routing with router.push and router.replace. is there a direct replacement that I can use? thanks!

fervent minnowBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

near oyster
#

useParams, usePathname seem useful so I started using them in the page router. not sure if this is ideal

near oyster
#

I think that only works in the app router right?

red tiger
#

if you use the pages router you should use next/router instead of next/navigation

near oyster
#

Gotcha. how about the other hooks such as useParams, usePathname? would it be fine to use those in page router? seems like they are supported

red tiger
#

any reasons you don't use useRouter().query and useRouter().pathname?

near oyster
#

I can. There are components that might be used in both app and page router during the migration so I was trying to see if it was possible to update those components to use these hooks first