nicnocquee / next-type-safe-routing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type-safe Next Routing

Utility to make next.js routing type safe. Based on https://www.flightcontrol.dev/blog/fix-nextjs-routing-to-have-full-type-safety. The project is initiated with typescript-starter.

Installation

npm i next-type-safe-routing

Usage

import { z } from 'zod';

export const OrgParams = z.object({ orgId: z.string() });

export const Routes = {
  home: makeRoute(({ orgId }) => `/org/${orgId}`, OrgParams),
};
import Link from 'next/link'
import {Routes} from '../../routes.ts'

<Link href={Routes.home({orgId: 'someId'})} />

Developing

  • npm run watch:build
  • To test: npm run test

About

License:MIT License


Languages

Language:TypeScript 100.0%