Last active
February 23, 2018 07:56
-
-
Save salipro4ever/68b17edaaa3a0035eca9a232c9f7f30f to your computer and use it in GitHub Desktop.
Two ways to define vue-route
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
| //app.js | |
| import VueRouter from 'vue-router'; | |
| import routes from './routes'; | |
| Vue.use(VueRouter); | |
| const router = new VueRouter({ mode: 'history', routes: routes}); | |
| const app = new Vue({ | |
| el: '#app', | |
| router //mandatory similar, because in ES6, {router} ~ {router: router} | |
| }); | |
| //routes.js | |
| export default [ | |
| { | |
| name: 'Home', | |
| path: '/', | |
| component: require('./components/Home.vue') | |
| }, | |
| { | |
| name: 'Example', | |
| path: '/example', | |
| component: require('./components/Example.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
| //app.js | |
| import VueRouter from 'vue-router'; | |
| import router from './routes'; | |
| const app = new Vue({ | |
| el: '#app', | |
| router | |
| }); | |
| //routes.js | |
| import Vue from 'vue' | |
| import Router from 'vue-router' | |
| import Hello from '@/components/Home' | |
| Vue.use(Router) | |
| export default new Router({ | |
| routes: [ | |
| { | |
| path: '/', | |
| name: 'Hello', | |
| component: Hello | |
| } | |
| ] | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment