vue子路由路径写/和不写/的差别

vue子路由路径写/和不写/的差别

路由的配置

  • 子路由写/的时候代表是绝对路径 跳转的时候直接在跟路径下跟上子路由
  • 不写/的时候 会进行拼接 在原有路径上跟上新的path路径
  • 如果父路由是/ 的时候 子路由写不写/都可以
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/login',
      component: () => import('@/02.form表单组件.vue')
    },
    {
      path: '/abc',
      component: () => import('@/layout.vue'),
      children: [
        {
          path: '/tree', 
          //子路由写了/代表绝对路径 跳转的时候 地址是这个http://localhost:8080/#/tree
          component: () => import('@/03.tree树形组件.vue')
        },
        {
          path: 'table', 
          //子路由没有写/ 代表的拼接的路径 跳转的时候地址是     http://localhost:8080/#/abc/table
          component: () => import('@/00.table表格.vue')
        }
      ]
    }
  ]
})

export default router
```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值