ethanniser / next-typesafe-url

Fully typesafe, JSON serializable, and zod validated URL search params, dynamic route params, and routing for NextJS.
https://next-typesafe-url.dev
MIT License
362 stars 16 forks source link

Hash usage isn't described in the docs #100

Open seregap opened 3 months ago

seregap commented 3 months ago

Is there a way of describing or using a hash? There is no mention of it in either the documentation or the examples.

This could be as follows:

$path({ route: "/product/[productID]", routeParams: { productID: 23 }, searchParams: { userInfo: { name: "bob", age: 23 } }, hash: "some-hash", })

// this generates the following string: // "/product/23?userInfo=%7B%22name%22%3A%22bob%22%2C%22age%22%3A23%7D#some-hash"

ethanniser commented 3 months ago

ha this has never come up before but definitely has a use case, I agree with your proposal, an additional optional string prop to $path

prs welcome

bring-shrubbery commented 2 months ago

Worth mentioning that hash is not passed to the server side by default, so it can only be used in client side hooks. This separation between server/client is quite a bit of a headache in this case.

@seregap I'd say you're better off just using $path({ ... }) + `#some-hash`.