美文网首页
命名路由

命名路由

作者: 冰点雨 | 来源:发表于2022-05-31 10:46 被阅读0次

    1.作用:简化路由的跳转
    2.如何使用

    给路由命名

    export default new VueRouter({
      routes: [
        {
          name:'zhuye',
          path: '/home',
          component: Home,
          children: [
            {
              name:'xiaoxi',
              path: 'message',
              component: Messages,
              children: [
                {
                  name:'xiangqing',
                  path: 'detail',
                  component: Detail
                }
              ]
            },
          ]
        }
      ]
    })
    

    简化跳转

    1.简化前,需要写完整的路径

    <router-link  to="/home/message/detail”>跳转</router-link>
    

    2.简化后,直接通过名字跳转

    <router-link  :to="{name:"xiangqing"}l”>跳转</router-link>
    

    3.简化后,配合传递参数

     <router-link
              :to="{
                name:'xiangqing',
                query: {
                  id: msg.id,
                  title: msg.title,
                },
              }"
              >跳转</router-link>
    

    相关文章

      网友评论

          本文标题:命名路由

          本文链接:https://www.haomeiwen.com/subject/injydrtx.html