Skip to content

Instantly share code, notes, and snippets.

@crookse
Last active November 28, 2019 15:01
Show Gist options
  • Save crookse/f97d94205a6dec534e5e0ccf3459b565 to your computer and use it in GitHub Desktop.
Save crookse/f97d94205a6dec534e5e0ccf3459b565 to your computer and use it in GitHub Desktop.
Vue: Automate Your Routing - bundle.js
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
// This code will parse through the route components and push the paths and meta data found in the
// `route` variable in each component. That data will be pushed to the `routes` variable and that
// `routes` variable will registerd in the Vue Router instance below.
let routes = [];
import routeComponents from "./routes.compiled.js"
routeComponents.forEach(component => {
component.route.paths.forEach(path => {
routes.push({
path: path,
component: component.default,
meta: component.route.meta
});
});
});
// Our Vue application needs to be imported so we can register it in the Vue instance below. Without
// it, we have no Vue application... duh.
import App from "../vue/app.vue";
// Create the Vue instance and mount it to the `#vue_app_mount` element in the index.html file.
window.app = new Vue({
el: "#vue_app_mount",
components: {
App
},
router: new VueRouter({
routes,
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment