首页 > 解决方案 > 未捕获的错误:导出导入时,路由配置中需要 [vue-router] “路径”

问题描述

请注意:

索引/搜索/功能是完全相同的代码,但名称不同,所有三个都有一个路径、组件、名称和元数据,如下所示。

注释/路由/routes.js

import Index from './index'
import Search from './search'
import Features from './features'

export default {
    Index,
    Search,
    Features
}

笔记/路线/index.js

import Index from '../components/index'

export default {
    name: 'notes.index',
    path: '/notes',
    component: Index,
    meta: {
        title: `Manage notes - Sort`,
    }
}

路由器.js

import Vue from 'vue'
import Router from 'vue-router'
import NoteRoutes from '@notes/routes/routes'

Vue.use(Router)

const routes = Array.prototype.concat(
    NoteRoutes,
);

const router = new Router({
    mode: 'history',
    routes
});

我正在连接每个模块中的所有 route.js 文件,然后将它们应用到路由器,但我仍然收到错误消息:

未捕获的错误:路由配置中需要 [vue-router] “路径”。

即使我所有的路线都有一条路径。如果我导入一个路由文件,让我们index.js直接说它可以工作,但在使用我的 routes.js 时不行,它只是该模块的所有路由的导出器。我在这里想念什么?

标签: javascriptvue.jsvuejs2vue-router

解决方案


你应该这样做

注释/路由/routes.js

import Index from './index'
import Search from './search'
import Features from './features'

export default [
    Index,
    Search,
    Features
]

路由.js

import Vue from 'vue'
import Router from 'vue-router'
import routes from '@notes/routes/routes'

Vue.use(Router)



const router = new Router({
    mode: 'history',
    routes
});

the way you did it. you actually get array with one item which contains all the routes object


推荐阅读