Skip to content

hasparus/strict-routes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strict-routes

zero-cost strictly typed routing in TypeScript


Have you ever broken a link in your app with a stupid typo or by overlooking? No more.

Usage

import { strictRoutes } from 'strict-routes';

type Routes =
  | '/'
  | 'posts/{postId}'
  | 'posts/{postId:number}/{commentId:string}'

const { navigate } = strictRoutes<Routes>()({
  navigate: (route) => console.log(route)
})

navigate('/');
navigate({ path: 'posts/{postId}', postId: 1 });
navigate({
  path: "posts/{postId}/{commentId}",
  postId: 20,
  commentId: "abcd",
});

Installation

yarn add strict-routes
npm install strict-routes

TypeScript Version

Because strict-routes is using template literal types it works with TypeScript 4.1 or newer.

About

zero-cost strictly typed routing in TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published