一、安装Vue Router
shell
npm install vue-router二、配置Vue Router
js
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const routes = [
{ path: '/', redirect: '/home' }, // 设置默认路由
{ path: '/home', component: () => import('@/components/Home.vue') },
{ path: '/about', component: () => import('@/components/About.vue') }
];
export default new Router({
mode: 'history',
routes
});三、使用Vue Router
html
<template>
<div id="app">
<router-view></router-view>
</div>
</template>