Skip to content

Commit e20757d

Browse files
committed
docs: add document for route configuration redirection
1 parent 61ffa60 commit e20757d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ const router = new Router({
121121

122122
> 通过过配置一个 path 为 `*` 的路由,可以处理所有的未匹配到的路由
123123
124+
#### 重定向
125+
126+
通过配置`routes`的配置项 `redirect` 可以实现重定向的功能
127+
128+
```javascript
129+
const router = new Router({
130+
routes: [
131+
{ path: '/foo', redirect: '/bar' }
132+
]
133+
}, driver)
134+
```
135+
136+
可以配置字符串、`location`、或者是一个方法
137+
138+
```js
139+
const router = new Router({
140+
routes: [
141+
{ path: '/foo', redirect: info => {
142+
const { query, params, hash } = info;
143+
return { name: 'bar' } // 或者 '/bar?a=2' 或者 {pathname: 'bar', query: {a: 2}}
144+
}}
145+
]
146+
}, driver)
147+
```
148+
149+
150+
124151
#### 动态注册路由
125152

126153
在一些场景,我们需要动态注册一部分路由,可以通过`router.registerRoutes`来注册,例子如下:

0 commit comments

Comments
 (0)