安装: npm install vue-router@4
路由:
// src/router/index.js文件
import {createRouter, createWebHistory} from "vue-router" import Home from ‘../views/Home.vue‘
const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes }) export default router
上述使用的是 history 模式,hash 模型需要做的改变如下(需将createWebHistory改为createWebHashHistory):
import { createRouter, createWebHashHistory } from ‘vue-router‘ const router = createRouter({ history: createWebHashHistory(), routes: [ //... ], })
原文:https://www.cnblogs.com/Maraitowa/p/14892935.html