Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addRoutes 只能添加在根路由上 不能在子路由上添加吗 #1256

Closed
yjj5855 opened this issue Mar 16, 2017 · 3 comments
Closed

addRoutes 只能添加在根路由上 不能在子路由上添加吗 #1256

yjj5855 opened this issue Mar 16, 2017 · 3 comments

Comments

@yjj5855
Copy link

yjj5855 commented Mar 16, 2017

const routes = [
  {
    name: 'app',
    path: '/',
    component: resolve => {
      require.ensure(['./page/app.vue'], () => {
        resolve(require('./page/app.vue'))
      }, 'app')
    },
    children: [
      ...homeRouter,
      ...userRouter,
      // ...demoRouter,
      ...settingRouter
    ]
  },
]

我想添加一个demoRouter 到 app 的子路由中 我是这样做的

$router.addRoutes([
    {
      $router.options.routes[0],
      children: [
        $router.options.routes[0].children,
        ...demoRouter
      ]
    }
])

目前这样做不行 报错[vue-router] Duplicate named routes definition: { name: "app", path: "" }
看到 V2.3.0 里有 overrideName 参数 但是感觉还是不太好操作

@posva
Copy link
Member

posva commented Mar 16, 2017

dup of #1156

@posva posva closed this as completed Mar 16, 2017
@PeiXueYang
Copy link

之所以会有这个警告是由于 路由中已经存在了这个路由 所以再次添加 会出现这个警告。

@PeiXueYang
Copy link

vue 中 路由重复添加的会被自动过滤掉,所以只会出现一个 warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants