tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
571 stars 23 forks source link

Hash in `Link`'s `href` is not allowed #85

Closed Elindorath closed 1 year ago

Elindorath commented 1 year ago

Hi there,

As I build up my codebase, I came on the use case of having a link with a hash to open a page scrolled on a specific id. While the original next/link component supports it (with the help of the scroll prop), the routes type definition generated by nextjs-routes prevents it as there is no hash possible in pathname.

I think this could be addressed with template literal string, but I wonder what do you think of it?

tatethurston commented 1 year ago

My inclination would be to cast or use next/link directly for the few call sites where this comes up.

I’m happy to look at a PR that investigates the template literal approach.

tatethurston commented 1 year ago

@Elindorath I missed that this was previously not possible with the UrlObject form. This has been fixed. Now you can do the following:

  // this will link to /foo#bar
  <Link href={{ pathname: "/foo", hash: "bar" }}>Foo</Link>