Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NextJS Dynamic Link for Page & Subpage

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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 ?

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading