router和route的区别和使用

router和route 区别:

1、跳转到当前路由的地址:
              不传参的形式: this.$router.push('/index')

              直接添加路径: this.$router.push('/index?from=login')

               query传参:

this.$router.push({
    path:'/index',
    query:{
      from:'login'     // 参数名称
    }
})

               params传参:

this.$router.push({
    path:'index',      // name
    params:{
      from:'login'     // 参数名称
    }
})

2、获取当前路由参数: this.$route.params.from

3、获取当前路由id: this.$route.params.id

4、获取当前路由地址:this.$route.path

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章