vue-router 踩坑

vue-router 填坑心得

跳转路由的方法

  • router-link标签
  • router.push(location, onComplete?, onAbort?) js去做
  • router.replace 区别是不添加history记录
  • 当然了a标签也是可以的
    除了嵌套路由,有时候还可以这样
<router-view class="view one"></router-view>
<router-view class="view two" name="a"></router-view>
<router-view class="view three" name="b"></router-view>

所以,不要小看路由的name属性

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        default: Foo,
        a: Bar,
        b: Baz
      }
    }
  ]
})

重定向与别名

const router = new VueRouter({
  routes: [
    { path: '/a', redirect: '/b' }
  ]
})

别名:
/a 的别名是 /b,意味着,当用户访问 /b 时,URL 会保持为 /b,但是路由匹配则为 /a,就像用户访问 /a 一样。

const router = new VueRouter({
  routes: [
    { path: '/a', component: A, alias: '/b' }
  ]
})

beforeRouteEnter
在这里插入图片描述

路由拦截,A->B,一般是在B页面中设置,和data平级,可以做一些处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值