关于vue-cli4.5.13中使用vue-router报错的问题。

以下是报错详情:

vue-router.esm-bundler.js?6c02:1474 Uncaught TypeError: Cannot read property 'forEach' of undefinedat createRouterMatcher (vue-router.esm-bundler.js?6c02:1474)at new createRouter (vue-router.esm-bundler.js?6c02:2777)at eval (index.js?a18c:41)at Module../src/router/index.js (app.js:1482)at __webpack_require__ (app.js:854)at fn (app.js:151)at eval (main.js:12)at Module../src/main.js (app.js:1470)at __webpack_require__ (app.js:854)at fn (app.js:151)

先附上自己的router/index.js代码:

import { createRouter, createWebHistory } from 'vue-router'const Home = ()=>import('views/home/Home')
const Category = ()=>import('views/category/Category')
const Cart = ()=>import('views/cart/Cart')
const Profile = ()=>import('views/profile/Profile')const routers = [{path:'',redirect:'/home'},{path:'/home',component:Home},{path:'/category',component:Category},{path:'/cart',component:Cart},{path:'/profile',component:Profile}
]
const router = new createRouter({history:createWebHistory(),routers
})export default router

百度了好多,发现都无济于事。于是自己寻找了半天发现在定义route数组的时候,把routes写成了routers。又因为在createRouter函数里面使用了简易写法,所以导致在参数里面找不到routes导致的报错。

下面附正确代码:

import { createRouter, createWebHistory } from 'vue-router'// 懒加载
const Home = ()=>import('views/home/Home')
const Category = ()=>import('views/category/Category')
const Cart = ()=>import('views/cart/Cart')
const Profile = ()=>import('views/profile/Profile')// 2.创建router
const routes = [{path:'',redirect:'/home'},{path:'/home',component:Home},{path:'/category',component:Category},{path:'/cart',component:Cart},{path:'/profile',component:Profile}
]const router = new createRouter({history:createWebHistory(),routes
})export default router

希望以后不要犯这种低级错误了

vue-router.esm-bundler.js?6c02:1474 Uncaught TypeError: Cannot read property ‘forEach‘ of undefined相关推荐

  1. types.js?a742:39 Uncaught TypeError: Cannot read property ‘prototype‘ of undefined at eval (type

    vue安装Element第三方组件库浏览器界面报错: types.js?a742:39 Uncaught TypeError: Cannot read property 'prototype' of ...

  2. Vue错误日记 ——关于Vue-Router出现esm-bundler.js?6c02:2127 Uncaught TypeError: Object(...) is no的解决方案

    Vue错误日记 --关于Vue-Router无法正常使用的解决方案 前言 配置 项目环境 项目代码 问题处理 结束语 前言 今天用 Vue-cli 搭建 Vue 项目时,发现Router无法正常挂载, ...

  3. 接上一篇:【Vue 项目打包后访问报错:Uncaught TypeError: Cannot read property 'call' of undefined】

    上一篇:Vue 项目打包后访问报错:Uncaught TypeError: Cannot read property 'call' of undefined 其实在修改 webpack.prod.co ...

  4. jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined

    Jquery DataTable使用报这个错: jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' o ...

  5. jquery.dataTables.min.js:62 Uncaught TypeError: Cannot read property ‘style‘ of undefined原因

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 报错: jquery.dataTables.min.js:62 Uncaught TypeError ...

  6. 运行JS代码报错:Uncaught TypeError: Cannot read property‘style‘ of undefined

    运行JS代码报错:Uncaught TypeError: Cannot read property'style' of undefined 这个报错的原因通常是没有获取指定的标签: 这个报错的原因通常 ...

  7. vue-cli3的项目 CDN链接报错解决 Uncaught TypeError: Cannot read property 'prototype' of undefined at Object.

    Uncaught ReferenceError: iview is not defined 出现这个问题的原因是路径的问题 确保你的路径是正确的,或者是既全局引入了iview,又按需引入,会造成这样的 ...

  8. Uncaught TypeError: Cannot read property ‘dispatch‘ of undefined

    一.背景描述 用VUE的时候报这个错 Uncaught TypeError: Cannot read property 'dispatch' of undefined 二.问题分析 1.我的代码是酱紫 ...

  9. Uncaught TypeError: Cannot read property ‘install‘ of undefined

    自学vue 刚搭建完项目 配置完路由就不好使了 一直报 Uncaught TypeError: Cannot read property 'install' of undefined 这个错误 //配 ...

最新文章

  1. 计算机视觉怎样实现自我超越?更大规模更精准的数据
  2. 听说又有兄弟因为用YYYY-MM-dd 被锤了...
  3. JQuery 获取自身的HTml代码
  4. 【机器学习】今天想跟大家聊聊SVM
  5. 这款堪称完美的PDF编辑器,帮你节省50%的写作时间
  6. 模块电源(二):电感式DC-DC升压器
  7. UE4 虚幻引擎,3D数学(一),3D坐标系,2D坐标系
  8. Hbase 二级索引示意图
  9. CSR867x — 蓝牙音频发射器方案(支持USB、模拟和SPDIF)
  10. 微信小程序登录-开发文档
  11. 谷歌浏览器保存网页为PDF
  12. 一个老程序员在情人节对中国软件业的致言!(转)
  13. 《测绘管理与法律法规》真题易错本
  14. 实例:用C#.NET手把手教你做微信公众号开发(8)--普通消息处理之链接(普通消息终结篇)
  15. css有哪些动画效果怎么实现的
  16. 灵魂显示正在登录聊天服务器,Soul跟随灵魂找到你
  17. v4l2 Camera详细设置
  18. WindowsForm切换窗口的几种常见实现
  19. 圆的周长面积(YZOJ-1020)
  20. 快速入门人工智能的方法及精要

热门文章

  1. 请收藏——QKL123!它能帮你挖掘项目价值(附2019年3月排行榜)
  2. 2022年5月英语口语素材积累
  3. 【教程】七天入门C#上位机目录
  4. 用matlab绘制抛物线y的x平方,利用matlab绘制多重x/y曲线
  5. Android音乐播放器开发(3)—注册
  6. 【pd.to_datetime】时间object转换datetime实例
  7. 中勒索病毒后的正确操作姿势
  8. 手机号码归属地查询,免费API
  9. 遇到人生低谷期该怎么度过?
  10. 直流电机的原理及驱动