next-typesafe-url
TypeScript icon, indicating that this package has built-in type declarations

4.0.7 • Public • Published

next-typesafe-url

Now with full support for app directory and server components!

Fully typesafe, JSON serializable, and zod validated URL search params, dynamic route params, and routing for NextJS.

Big shoutout to tanstack/router and yesmeck/remix-routes for inspiration and ideas.

Whats wrong with curent solutions?

Routing

Next.js's non-typesafe routing can lead to runtime errors and make it difficult to catch routing-related issues during development, as it relies on string literals instead of type-safe constructs.

Search Params

from tanstack/router:

Traditional Search Param APIs usually assume a few things:

  • Search params are always strings
  • They are mostly flat
  • Serializing and deserializing using URLSearchParams is good enough (Spoiler alert: it's not, it sucks)

Typesafety Isn’t Optional

How does next-typesafe-url solve these problems?

  • Fully typesafe routing- all the way from the route, to the route params, to the search params
  • Search params are JSON-first, so you can pass strings, numbers, booleans, nulls, and even nested objects and arrays
  • Search and route params are validated at runtime using zod, so you can be sure that the data you get matches the schema you expect

Documentation

PLEASE READ THE DOCS

Package Sidebar

Install

npm i next-typesafe-url

Weekly Downloads

1,268

Version

4.0.7

License

MIT

Unpacked Size

96.6 kB

Total Files

31

Last publish

Collaborators

  • whatplan