vue-router动态添加路由报错

这一生的挚爱 提交于 2019-12-04 06:26:17

【报错】

Uncaught Error: [vue-router] route config "component" for path: /home cannot be a string id. Use an actual component instead

运行时不报错,但是页面显示空白。打开控制台显示下图:

.

【报错解析】

路径/home的[vue router]route config“component”不能是字符串id 请改用实际的组件

在以下代码中定位,可以看到是组件的错误component

export default new Router({
  routes: [
    {
      path:'/',
      redirect:'/home'
    },
    {
      path:'/home',
      component:'Home'
    },
    {
      path:'/cart',
      component:'Cart'
    },
    {
      path:'/profile',
      component:'Profile'
    }
  ]
})

发现  component:'Profile' 不能加引号

【解决方法】

去掉引号(component:Profile)后界面即可正常显示。

 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!