项目
在 GitHub 查看 
zoontek/chicane
关于
适用于 React 和 TypeScript 的简单、安全路由器。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文@zoontek/chicane
A simple and safe router for React and TypeScript.
Design principles
- Typed routes: improving the DX, and making sure all your params are here!
- Component-friendly: the router nicely fits in your React app.
- Easy-to-use: naming routes instead of moving around unsafe URLs.
- Performant: avoids any unnecessary render.
Installation
$ yarn add @zoontek/chicane
# --- or ---
$ npm install --save @zoontek/chicane
Links
- 📘 Documentation
- ⚖️ License
Quickstart
import { createRouter } from "@zoontek/chicane";
import { match } from "ts-pattern";
const Router = createRouter({
Home: "/",
Users: "/users",
User: "/users/:userId",
});
const App = () => {
const route = Router.useRoute(["Home", "Users", "User"]);
// route object is a discriminated union
return match(route)
.with({ name: "Home" }, () => <h1>Home</h1>)
.with({ name: "Users" }, () => <h1>Users</h1>)
.with({ name: "User" }, ({ params }) => <h1>User {params.userId}</h1>) // params are strongly typed
.otherwise(() => <h1>404</h1>);
};
Run the example app
$ git clone [email protected]:zoontek/chicane.git
$ cd chicane/example
$ yarn install && yarn dev
# --- or ---
$ npm install && npm run dev
🙌 Acknowledgements
- react-router for the
historyand theLinkcreation code. - reach-router for the path ranking algorithm.
探索相关项目
加载中…