I have a Nextjs application. The app will grow to a nice size (200 pages)
What is the best way to manage links. Some pages will have navigation buttons and and hrefs, hyperlinks.
I am looking for solution to manage
Example: pages -> about, contact, support, home, blog. But when you have 200 pages and you are hardcoding <a href="/about"> </a>
if I delete or change the about page name I have to go in all 200 pages and update this
2
Answers
Navigate with click :
Navigate with Link :
And if you have 200 url you should make 200 links you cannot optimize that, but you can create a file for all your link then import it everywhere and when you have to update one
path
you do it inside this file :and from the file in which you want to navigate :
I create a routes file with all my hard-coded routes and use the
const
throughout my app. I use trailing slash, so they need to be appended to all routes.This setup works well for me, and I’ve used it on numerous projects with hundreds of routes. It saved a lot of time over the years when inevitably, I needed to change a route’s
href
or name.My routes file is similar to this:
I use them like
On larger projects, I break the routes out into separate files.