-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
58 lines (50 loc) · 1.36 KB
/
index.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { createRouter, createWebHistory } from "vue-router";
import MainView from "@/views/MainView.vue";
import OOBEView from "@/views/OOBEView.vue";
import NoteView from "@/views/NoteView.vue";
import WelcomeView from "@/views/WelcomeView.vue";
import { has } from "@/utils/helpers";
const scrollPositionMap = new Map<string, number>();
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
scrollBehavior: (to) => {
const pageWrapper = document.getElementById("PageWrapper");
if (!pageWrapper) return;
const position = scrollPositionMap.get(to.fullPath);
pageWrapper.scrollTop! = position || 0;
},
routes: [
{
path: "/",
name: "main",
component: MainView,
children: [
{
path: "/note/:id(\\d+)",
name: "note",
component: NoteView,
},
{
path: "/",
name: "welcome",
component: WelcomeView,
},
],
},
{
path: "/_oobe",
name: "oobe",
component: OOBEView,
},
],
});
router.beforeEach((to, from) => {
if (!has("LP_OOBE_PASSED") && to.name !== "oobe") {
return { name: "oobe" };
}
const pageWrapper = document.getElementById("PageWrapper");
if (!pageWrapper) return;
scrollPositionMap.set(from.fullPath, pageWrapper.scrollTop);
return true;
});
export default router;