mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-25 11:28:13 +08:00
28 lines
725 B
TypeScript
28 lines
725 B
TypeScript
import type { Router } from 'vuepress/client'
|
|
import { nextTick } from 'vue'
|
|
import { inBrowser } from '../utils/index.js'
|
|
import { useScrollPromise } from './scroll-promise.js'
|
|
|
|
export function enhanceScrollBehavior(router: Router) {
|
|
router.options.scrollBehavior = async (to, from, savedPosition) => {
|
|
await useScrollPromise().wait()
|
|
if (savedPosition)
|
|
return savedPosition
|
|
if (to.hash)
|
|
return { el: to.hash, top: 64 }
|
|
return { top: 0 }
|
|
}
|
|
|
|
router.beforeEach(() => {
|
|
if (inBrowser) {
|
|
document.documentElement.classList.remove('smooth')
|
|
}
|
|
})
|
|
|
|
router.afterEach(() => nextTick(() => {
|
|
if (inBrowser) {
|
|
document.documentElement.classList.add('smooth')
|
|
}
|
|
}))
|
|
}
|