Skip to content

Commit 2ca4568

Browse files
committed
feat: add delayed scrolling behavior to hash links
1 parent 1a2c9d2 commit 2ca4568

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

apps/web/src/router/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { createRouter, createWebHistory, type RouteLocationNormalized, type RouteLocationNormalizedLoaded } from 'vue-router'
55
import { routes } from '@/router/routes'
6+
import { RouteName } from '@/types'
67

78
export const router = createRouter({
89
history: createWebHistory(process.env.BASE_URL),
@@ -11,7 +12,14 @@ export const router = createRouter({
1112
return savedPosition
1213
}
1314
if (to.hash) {
14-
return { el: to.hash }
15+
return new Promise((resolve) => {
16+
setTimeout(
17+
() => {
18+
resolve({ el: to.hash, behavior: 'instant' })
19+
},
20+
from.name === RouteName.ProgramFromProjectDetail ? 500 : 0
21+
)
22+
})
1523
}
1624
return { top: 0 }
1725
},

0 commit comments

Comments
 (0)