0

Using NextJS I Have Dynamic Pages and Dynamic SubPages.

Here is Folders/Files :

pages
├── [Formation]
├── index.js
│   ├── [SubPage].js

In index.js (Formation Page), I Create Links :

<Link href={`[Formations]/[SubPage]`} as={`${Title}/${item}`}>{item}</Link>
<Link href="ReactJS/Udemy">Udemy</Link>

The First One is what I use to navigate to Subpage. But It's not Working the way it should. Navigation is correct, but It Reload the entire page and my Layout in _app.js

The Second is a Test, and it's working, it does not reload the Layout

Both Create the same <a> Tag

Do you know Why the first one isn't working ?

1 Answer 1

1

Looks like you are following the old way to handle dynamic route in NextJs. Since the as prop is a simple decorator and href the path your are trying to navigate to, consider doing:

<Link href={`${Title}/${item}`}>{item}</Link>
1
  • 1
    That was so simple... Thanks dude, it's working. Sorry to have disturbed you for this. When I first Tried this, I had an error so thought this was not the solution, and didn't retried
    – Lucas
    Feb 15, 2023 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.