#Router
1 messages · Page 1 of 1 (latest)
@eternal saddle
What do you get if you just render the currentRoute inside the component?
it returns null.
I checked this which is the new process for next 13 https://beta.nextjs.org/docs/api-reference/use-selected-layout-segment#creating-an-active-link-component
But is there another way or a simple way to do this?
I'm creating a Navbar and adding a className if it's active Link
If I check the router, it returns this value:
It should work, I am doing it exactly the same way in Next 13.
It is possible the issue comes from something higher up.
How are you importing useRouter and how are you implementing it?
Can you share more relevant code?
You can see how I implemented it in Next 13 here:
https://github.com/w3bdesign/dfweb-v3/blob/master/src/components/Layout/Navbar.component.tsx
🚀 DFWeb portfolio version 3 with Next.js, Sanity.io, Framer Motion, Storybook, Tailwind CSS, Cypress, Playwright and more - dfweb-v3/Navbar.component.tsx at master · w3bdesign/dfweb-v3
I'm importing the useRouter now from next/navigation since I'm getting an error that the NextRouter is not mounted if I'm importing it from next/router.
I've added the "use client" in the component since I use useState in it.
Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted at Navbar (./app/Navbar.jsx:24:74)
Exact error on my end
Try import { useRouter } from "next/router"
And try removing "use client"
It could be that it works differently if you use the app directory
I think it is. I'm new to Next JS as they mentioned that Next 13 is quite an upgrade. So tried playing with it. I think I need to create another component to avoid using it as client so useRouter can be used. Thank you for the details. I really appreciate it 😄
Yeah, the app directory feature is considered a beta release
It can have some bugs and issues
You can use Next 13 without the app directory, though
I'm actually exploring the new features of Next 13 that's why I'm using these experimental. Researched further and found this:
https://github.com/vercel/next.js/issues/43585
So basically, the NextRouter is not mounted is already a common issue. Might need to downgrade to 13.0.2 for the meantime as mentioned in the post.