安装vue-router
npm install vue-router@4.0.0-beta.13
创建src/router/index.js
import { createRouter, createWebHashHistory } from 'vue-router' const router = createRouter({ history: createWebHashHistory(), // hash模式:createWebHashHistory,history模式:createWebHistory routes: [ { path: '/', redirect: '/home' }, { path: '/home', name: 'home', component: () => import(/* webpackChunkName: "home" */ '@/views/home.vue'), meta: { index: 1 } }, { path: '/test', name: 'test', component: () => import(/* webpackChunkName: "login" */ '@/views/testDemo.vue'), meta: { index: 1 } } ] }) export default router
main.js中
import router from './router'
app.use(router)