title: Vue.js: addRoutes method with array from API call
body: <p>I am going to use the addRoutes method for the first time. I didn't find any full tutorials of how developers can use this method so I decided to try and ask here.</p>
  
  <p>In my app I have some sort of CMS so a user can create new pages with custom paths. In my router/index.js file where I import components and declare their routes I need to add these custom routes.</p>
  
  <p>I have an API endpoint which can give me a JSON with arrays of these routes. How can I call this endpoint in my router/index.js file and add these new routes to my router?</p>
  
  <p>Here is what I have in my router.index.js file (I added its structure rather than code itself):</p>
  
  <pre><code>import Vue from 'vue';
  import VueRouter from 'vue-router';
  import http from '../http';
  import config from '../config';
  import Home from '../components/pages/Home';
  
  Vue.use(VueRouter);
  
  const router = new VueRouter({
   mode: 'history',
   routes: [
    {
     path: '/home',
     name: 'home',
     component: Home,
    },
    ...
    ],
  });
  
  router.addRoutes([]);
  
  export default router;
  </code></pre>