[vue] 命名路由

步骤

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

  2. 如何使用

    1. 给路由命名:
    {
          
          
    	path:'/demo',
    	component:Demo,
    	children:[
    		{
          
          
    			path:'test',
    			component:Test,
    			children:[
    				{
          
          
                          name:'hello' //给路由命名
    					path:'welcome',
    					component:Hello,
    				}
    			]
    		}
    	]
    }
    
    1. 简化跳转:
    <!--简化前,需要写完整的路径 -->
    <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>
    

猜你喜欢

转载自blog.csdn.net/qq_14993591/article/details/121318081
今日推荐