0.1.5 • Published 5 years ago
@tancc/router v0.1.5
這是一個非常小而且基礎的 router 套件,扣掉型別定義整體不到 100 行 (目前只是造輪子玩一下而已,不一定會繼續更新呵呵)
安裝
yarn
使用
import { Router, createBrowserHistory } from 't-router'
// 1. 定義 route。支援動態載入
const routes = [
{
path: '/',
component: Home
},
{
path: '/home/:userId',
getComponent: () => import('./User').then(module => module.default)
}
]
// 2. 定義 history
const h = createBrowserHistory()
// 3. 回傳 Router component
const App = () => <Router routes={routes} history={h} />
開發
yarn bundle && cd ./example && yarn
yarn start