路由哈希模式更换为历史模式
步骤
- 将路由替换为history模式
- 更换配置文件中配置的根路径
- 查找项目中存在的哈希跳转
将路由替换为history模式
import {
createRouter,
createWebHistory,
} from 'vue-router'
const router = createRouter({
history: createWebHistory(), //可指定根路径
routes,
})
更换配置文件中配置的根路径
此处为vite.config.ts
export default defineConfig({
base: '/', // 设置打包路径
})
查找项目中存在的哈希跳转
全局搜索
(`#/ 替换为 (`/
若存在 location.replace
需替换成 router.replace
否则页面会刷新