Przeglądaj źródła

Update 修改路由历史模式

YueYunyun 2 lat temu
rodzic
commit
341a186930
1 zmienionych plików z 11 dodań i 4 usunięć
  1. 11 4
      UI/VAP.Vue/src/router/index.ts

+ 11 - 4
UI/VAP.Vue/src/router/index.ts

@@ -1,6 +1,6 @@
 /* eslint-disable @typescript-eslint/restrict-template-expressions */
 /* eslint-disable @typescript-eslint/no-base-to-string */
-import { createRouter, createWebHashHistory, type RouteRecordRaw } from "vue-router"
+import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router"
 import appStore from "@s"
 import configs from "@@/config"
 import JwtService from "@@/services/JwtService"
@@ -103,13 +103,20 @@ export const constantRoutes: RouteRecordRaw[] = [
 ]
 
 const router = createRouter({
-	history: createWebHashHistory(),
+	//history: createWebHashHistory(),
+	history: createWebHistory(),
 	routes: constantRoutes,
-	scrollBehavior(_to, _from, savedPosition) {
+	scrollBehavior(to, _from, savedPosition) {
 		if (savedPosition) {
 			return savedPosition
+		} else if (to.hash) {
+			return {
+				el: to.hash,
+				top: 80,
+				behavior: "smooth"
+			}
 		} else {
-			return { top: 0 }
+			return { top: 0, left: 0, behavior: "smooth" }
 		}
 	}
 })