在项目中,想让路由后缀为空,或者index的时候,都跳转到路由为index的页面,于是在router中如下配置

routes: [{
    path: '/',
    name: 'index',
    component: () => import('@/components/index').then(m => m.default)
  },{
    path: '/index',
    name: 'index',
    component: () => import('@/components/index').then(m => m.default)
  }]

但是浏览器告警信息 [vue-router] Duplicate named routes definition: { name: "index", path: "/index" }

因为路由重复添加,name一样造成,利用redirect重定向

routes: [{
    path: '/',
    redirect: {
      name: index
    }
    // name: 'index',
    // component: () => import('@/components/index').then(m => m.default)
  },{
    path: '/index',
    name: 'index',
    component: () => import('@/components/index').then(m => m.default)
  }]

 

Logo

前往低代码交流专区

更多推荐