An open API service indexing awesome lists of open source software.

https://github.com/hasparus/strict-routes

zero-cost strictly typed routing in TypeScript
https://github.com/hasparus/strict-routes

Last synced: about 1 year ago
JSON representation

zero-cost strictly typed routing in TypeScript

Awesome Lists containing this project

README

          

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

```ts
import { strictRoutes } from 'strict-routes';

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

const { navigate } = strictRoutes()({
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](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types) it works with TypeScript 4.1 or newer.