Dynamic nested routes
Answered
Barbary Lion posted this in #help-forum
Barbary LionOP
In my routes structure (using Pages router) I have nested dynamic routes in the form of /[category]/[slug].tsx. Whenever I navigate towards the category section I don't seem to have any issues, but once I navigate into the slug route and try to navigate back to the category using the navigation bar, I get taken to /[category]/selected-category.
Answered by Barbary Lion
After deeper troubleshooting, I noticed that I wasn't prefixing my href tags with the '/' in my Link components. After modifying it, I was able to solve the issue.
Before fixing:
After fixing:
Before fixing:
<Link href={item.category.slug}>
...
</Link>After fixing:
<Link href={`/${item.category.slug}`}>
...
</Link>2 Replies
Giant panda
I would love the answer to this as well. I had to use a absolute path because I had a random [id] in the url when attempting to use relative path instead of it self populating.
@Giant panda I would love the answer to this as well. I had to use a absolute path because I had a random [id] in the url when attempting to use relative path instead of it self populating.
Barbary LionOP
After deeper troubleshooting, I noticed that I wasn't prefixing my href tags with the '/' in my Link components. After modifying it, I was able to solve the issue.
Before fixing:
After fixing:
Before fixing:
<Link href={item.category.slug}>
...
</Link>After fixing:
<Link href={`/${item.category.slug}`}>
...
</Link>Answer