Better Nextjs Routes #83256
jonkwheeler
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
href
creation combiningpath
,params
,searchParams
, andhash
.Non-Goals
next/link
componentBackground
I believe the current typings for routes in next.js are lacking. I also do not believe they should be baked into the
next/link
component as they are today. Instead of a feature flag for adoption, import a helper function to opt-in and help build your fully typed route.Proposal
During dev and build, run a script to scan the
app/pages
directory. I will show code for theapp
directory, but addingpages
compatibility would be easy.This simple script makes an array of static and dynamic routes. Here is an example output for the
routeTree.gen.ts
file.Lastly, this is utilized in a new
route
function which can acceptpath
,params
,searchParams
, andhash
.path
andparams
are fully typed.Forward Thinking
Add pages compatibility.
A future improvement could be to allow a passed type from the user for
params
,searchParams
, andhash
. Meaning, if you have/product/[productType]
, you could createBeta Was this translation helpful? Give feedback.
All reactions