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
- Host: GitHub
- URL: https://github.com/hasparus/strict-routes
- Owner: hasparus
- Created: 2020-09-27T15:03:23.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-09-27T16:23:22.000Z (over 5 years ago)
- Last Synced: 2024-10-19T05:18:24.776Z (over 1 year ago)
- Language: TypeScript
- Size: 10.7 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.