[Vuejs]-Vue-router not rendering component when dynamically importing components

0👍

You have two options…

  1. Wait till all your imports resolve before creating your router. This would involve being able to postpone the creation of your root Vue instance
  2. Create your router using lazy-loaded components.

I would recommend option #2

new VueRouter({
  mode: 'history',
  routes: data.map(page => { // data as defined in your GetAllPages function
    const pageTitle = page.title.rendered.toLowerCase()
    return {
      path: `/${pageTitle}`,
      name: pageTitle,
      component: () => import(`../pages/${pageTitle}.js`)
    }
  })
});

Leave a comment