Created
December 11, 2019 17:50
-
-
Save kevinmpowell/708825466588998f750a89b9b147723b to your computer and use it in GitHub Desktop.
Simple Router Example For Vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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