Follow these instructions to create an auto-import of the router files in your project that will handle the router files inside a specific folder:
- With our route files created and placed inside the routes folder, we need to make sure that every route file has a default export object in it. In the index.js file, inside the src/router folder, remove the default array of routes that is present in the file:
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
export default new VueRouter({});
- Now create an empty array of routes that will be populated by the imported ones from the folder, and start the import. With that, requireRoutes will be an object with the keys being the filename and the values being the ID of the file:
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const routes = [];
const requireRoutes = require.context(
'./routes',
true,
/^(?!.*test).*\.js$/is...