

const Foo : {template: '<p> this is foo </p>
const Bar : {template: '<p> this is bar </p>
.....2、定义路由
const routes: [
{path: '/foo', component: Foo},
{path: '/bar', component: Bar}
]3、创建路由实例,传入定义路由的配置
const router = new VueRouter({
routes: routes
})4、创建挂载根实例
const app = new Vue({
router: router
}).$mount('#app')HTML
<!--外部链接--><script src="https://unpkg.com/vue/dist/vue.js"></script><script src="https://unpkg.com/vue-router/dist/vue-router.js"></script><p id="app"> <h1>Hello</h1> <p> <router-link to="/foo">Go to Foo</router-link> <router-link to="/bar">Go to Bar</router-link> </p> <router-view></router-view></p>
