Skip to content

Commit

Permalink
总结命名路由
Browse files Browse the repository at this point in the history
  • Loading branch information
Panyue-genkiyo committed Oct 11, 2021
1 parent bd5e6e0 commit c40c125
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,52 @@ module.exports = {
$route.query.id
$route.query.title
```

### 5.命名路由

1. 作用:可以简化路由的跳转。

2. 如何使用

1. 给路由命名:

```js
{
path:'/demo',
component:Demo,
children:[
{
path:'test',
component:Test,
children:[
{
name:'hello' //给路由命名
path:'welcome',
component:Hello,
}
]
}
]
}
```

2. 简化跳转:

```vue
<!--简化前,需要写完整的路径 -->
<router-link to="/demo/test/welcome">跳转</router-link>
<!--简化后,直接通过名字跳转 -->
<router-link :to="{name:'hello'}">跳转</router-link>
<!--简化写法配合传递参数 -->
<router-link
:to="{
name:'hello',
query:{
id:666,
title:'你好'
}
}"
>跳转</router-link>
```

0 comments on commit c40c125

Please sign in to comment.