javascript - 未捕获的错误:导出导入时,路由配置中需要 [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 时不行,它只是该模块的所有路由的导出器。我在这里想念什么?
解决方案
你应该这样做
注释/路由/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
推荐阅读
- javascript - 缩放地图的容器 div,map.invalidateSize() 不起作用
- google-cloud-datastore - 数据存储区 - 分配最大长度的 ID
- python-3.x - 为什么将值附加到所有玩家而不是一次?
- google-cloud-firestore - 错误 - 警告,FIREBASE_CONFIG 环境变量丢失。初始化 firebase-admin 将失败
- python - UnboundLocalError at / local variable 'context' 在赋值之前引用
- react-native - 扫描错误博览会:网络响应超时
- google-data-studio - 如何计算 Data Studio 数据透视表中两列之间的概率差异?
- javascript - 构建传递查询字符串的 window.location.href
- python - 比萨挑战。打印比萨订单的账单
- xslt - XSLT - 用特定字符分隔的分割字符串