Pattern for Next.js path strings (App Router)
Does anyone have a good strategy for handling the paths to different pages in next? I'm using the app router but I moved some files around which adjusted the url paths for all the pages, and now I'm paranoid that I have dangling hrefs and router.push-es pointing to the old paths.
Makes me think there has to be a better way to manage the strings of where things are routed.
Long ago in my Ruby on Rails days they had amazing path helpers where you would never link or reference any path directly you would call a helper that would generate the path string and that way you never had to worry about linking to old paths.
Anyways, anyone know a good way of handling this in next+app router? Maybe there's something obvious I'm missing.
5 Replies
there are some options for that
iirc vercel seems to be working with something for that
but nothing concrete for now
Thanks for this! This led me down a rabit hole and I also found this solution which is a bit less typesafe but seems a bit more plug and play:
https://github.com/tatethurston/nextjs-routes
Still deciding on which one to go with.
GitHub
GitHub - tatethurston/nextjs-routes: Type safe routing for Next.js
Type safe routing for Next.js. Contribute to tatethurston/nextjs-routes development by creating an account on GitHub.
Look like this is the up and coming static types for routes in the app dir:
https://nextjs.org/blog/next-13-2#statically-typed-links
https://nextjs.org/docs/app/building-your-application/configuring/typescript#statically-typed-links
https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes