Skip to content

一、安装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>

MIT版权,未经许可禁止任何形式的转载