Skip to content

Commit

Permalink
Create README_zh.md
Browse files Browse the repository at this point in the history
  • Loading branch information
iuroc authored Dec 12, 2023
1 parent e9b53d5 commit ad2b220
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# vanjs-router

> 基于 Van.js 的前端路由控制系统
[English](./README.md) | [简体中文](./README_zh.md)

## 安装

安装 `van.js``vanjs-router`

```
npm install vanjs-core vanjs-router
```

## 导入使用

```typescript
import van from 'vanjs-core'
import { router, Route } from 'vanjs-router'

const { div } = van.tags

const App = () => {
return div(
Route(0, div('这是 ID 为 0 的页面')),
Route(1, div('这是 ID 为 1 的页面')),
Route(2, div('这是 ID 为 2 的页面')),
)
}

const routeId = router()
```

## 设置路由事件

```typescript
const routeId = router(add => {
add(0, () => {
console.log('当前位于 ID 为 0 的页面')
})
add(0, () => {
console.log('事件叠加')
})
add(1, () => {
console.log('当前位于 ID 为 1 的页面')
})
})
```

## 切换路由

```typescript
Route(0,
button({
onclick() { routeId.val = 1 }
}, '跳转到 ID 为 1 的页面')
)
Route(1, '这里是 1')
```

0 comments on commit ad2b220

Please sign in to comment.