ckastbjerg / next-type-safe-routes

Never should your users experience broken links again!
MIT License
70 stars 5 forks source link

Support catch all routes #13

Closed ckastbjerg closed 3 years ago

ckastbjerg commented 3 years ago

This will enable the following use cases with the getRoute util:

getRoute("/optional-catch-all");
getRoute({ route: "/optional-catch-all", path: "/a/b/c" });
getRoute({ route: "/catch-all", path: "/a/b/c" })
getRoute({
  route: "/nested-catch-all/[dynamic]/slugs",
  params: { dynamic: 1 },
  path: "/a/b/c",
})

Or with an abstraction on top of the next/link component:

<Link to="/optional-catch-all">Optional catch all (no path)</Link>
<Link to={{ route: "/optional-catch-all", path: "/a/b/c" }}>
  Optional catch all
</Link>
<Link to={{ route: "/catch-all", path: "/a/b/c" }}>
  Catch all
</Link>
<Link
  to={{
    route: "/nested-catch-all/[dynamic]/slugs",
    params: { dynamic: 1 },
    path: "/a/b/c",
  }}
>
  Nested catch all (with params)
</Link>