如何向vue组件添加外部布局

时间:2019-02-18 00:55:29

标签: vue.js vue-router

我想将Vue路线从/ dashboards / dashboard更改为/ dashboard。如何使用此代码实现这些目标

import Layout2 from '@/layout/Layout2'

export default [
{
    path: '/dashboards',
    component: Layout2,
    children: [
    {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/components/dashboards/Dashboard')
    }
    ]
  }
]

我尝试放置这些代码,但是如果已经添加了组件,如何添加layout2?

export default [
  {
    path: '/dashboard',
    name: 'dashboard',
    component: () => import('@/components/dashboards/Dashboard')
  }
]

1 个答案:

答案 0 :(得分:1)

如果vue-router document

  

请注意,以/开头的嵌套路径将被视为根   路径。这使您无需利用组件嵌套即可   使用嵌套的URL。

你可以

import Layout2 from '@/layout/Layout2'

export default [
{
    path: '/',
    component: Layout2,
    children: [
    {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/components/dashboards/Dashboard')
    }
    ]
  }
]