search

Home  >  Q&A  >  body text

javascript - Dynamically adding routing error

I dynamically added a route and then an error was reported. The code for adding dynamic routing is as follows. Data is the data obtained from the background. I wrote a 404 page myself, and path: '/404' did not have this error.

data.permission = [{
    path: '/index',
    name: 'index',
    component: './../views/layout/index'
}]
this.$router.addRoutes(data.permission)

Then the following error is reported, please solve it

Uncaught (in promise) Error: [vue-router] route config "component" for path: /index cannot be a string id. Use an actual component instead.
typechotypecho2742 days ago935

reply all(2)I'll reply

  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-07-05 10:51:44

    Add a require in the component field, the error message was misunderstood

    component:require('./../views/layout/index.vue')

    reply
    0
  • 欧阳克

    欧阳克2017-07-05 10:51:44

    component requires a component instance and cannot give a path
    It can be introduced through import or require

    reply
    0
  • Cancelreply