vue-router重定向

在router下的index.js配置路由时,有时候,配置不同的路由,但是,希望跳转到同一个页面,这个时候就需要使用redirect进行重定向,这样,就可以跳转到同一个页面。

普通的重定向(不需要传递任何的参数):

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
      children: [
        {//在地址为空时,直接跳转cell路由
          path:'',
          redirect:'/cell'
        },
        {
        path: '/cell',
        component: Cell
      }]
    }
  ]
})

在重定向时,不需要配置component组件,只需要配置redirect,设置重定向的路由。

重定向时需要传递参数

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
      children: [
        {//在地址为空时,直接跳转cell路由
          path:'',//默认缺省值
          redirect:'/cell'
        },
        {
        path: '/cell',
        component: Cell
      },{
        path:'/city/:cityid',
        component:City
      },{
        //本来配置的路由路径  /city/:cityid 是一个城市页面 传递的参数为 cityid 但是 我们可以设置重定向 /province/:cityid 同样到城市页面
        path:'/province/:cityid',
        redirect:'/city/:cityid'
      }]
    }
  ]
})

vue-router剖析—03 重定向和别名、编程式路由

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值