不要问我借钱,大家都是同样的年纪,你没有钱,我能有吗?
【26.Vue Router--路由的命名
】
-
作用:可以简化路由的跳转。
-
如何使用
-
给路由命名:
{ path:'/demo', component:Demo, children:[ { path:'test', component:Test, children:[ { name:'hello' //给路由命名 path:'welcome', component:Hello, } ] } ] }
-
简化跳转:
<!--简化前,需要写完整的路径 --> <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>
-
- 跳转多级路由时,to=“路由路径” 要写全!从一级路由开始写!(如:
to="/demo/test/welcome"
) - 可以给路由配置
name属性
,传递参数的时候会用到,添加name属性后跳转就不用写全路径,可以直接写路由的name (:to="{name:'hello'}"
)【有冒号】