Vue Router系列之(六)命名路由

命名路由

命名路由:给你的路由规则起个名字

  1. 作用:可以简化路由的跳转【路由层级比较多时】。

  2. 如何使用

    1. 给路由规则命名:

      {
      	path:'/demo',
      	component:Demo,
      	children:[
      		{
      			path:'test',
      			component:Test,
      			children:[
      				{
                            name:'hello' //通过name属性给路由规则命名
      					path:'welcome',
      					component:Hello,
      				}
      			]
      		}
      	]
      }
      
    2. 简化跳转:

      <!--简化前,需要写完整的路径 -->
      <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>
      
posted @ 2024-02-29 19:55  刘二水  阅读(150)  评论(0)    收藏  举报