Skip to content

Instantly share code, notes, and snippets.

@kevinmpowell
Created December 11, 2019 17:50
Show Gist options
  • Save kevinmpowell/708825466588998f750a89b9b147723b to your computer and use it in GitHub Desktop.
Save kevinmpowell/708825466588998f750a89b9b147723b to your computer and use it in GitHub Desktop.
Simple Router Example For Vue
import Vue from 'vue'
import App from './App.vue'
import Form from './Form.vue'
Vue.config.productionTip = false
const NotFound = { template: '<p>Page not found</p>' }
const routes = {
'/': App,
'/form': Form
}
new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname
},
computed: {
ViewComponent () {
return routes[this.currentRoute] || NotFound
}
},
render (h) { return h(this.ViewComponent) }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment