Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

React | Dynamic routing not working for direct navigating?

Hi! React newbie here and probably not the place to ask but I figured I'd give it a shot.

I'm working on a NextJs project and have run into a snag with my routing. I have dynamic routing set up like instagram/[userID]/posts/[postId] & instagram/[userId]/posts - this works great if I navigate from my <Link> elements. However when I type into the browser instagram/1/posts I return 0 results. When using useRouter().query it returns an empty object.

Not quite sure what I'm doing wrong here but I'd love to learn!

1 Answer

Hi mckbas,

I kind of got a part of your questions. It will be great if you can share the code of your dynamic pages or you can just share the link of code sandbox.

I tried creating the same structure of routes and it working totally fine on my end on page reload.

You can review my code (here)[https://codesandbox.io/s/tender-ptolemy-ctz4e] I tried to run it on local as well it is working same as expected.

Thanks,