peng
2026-03-18 af8a72f0f43279cfe778af0ba683917032d95746
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from '@/config/router.config'
 
/**
 * 解决Redirected from “xxx“ to “xxx“ via a navigation guard
 */
const originalPush = Router.prototype.push
Router.prototype.push = function(location, onComplete, onAbort) {
  if (onComplete || onAbort) {
    return originalPush.call(this, location, onComplete, onAbort)
  }
  return originalPush.call(this, location).catch(err => err)
}
 
Vue.use(Router)
 
function createRouter() {
  return new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
  })
}
 
const router = createRouter()
 
/**
 * 退出登录时主动调用
 * 清空路由,解决再次登录时出现路由命名重复的warning
 */
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
 
export default router