aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs/app/router.options.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-19 17:30:39 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-19 17:30:39 +0800
commit3adc965dd09490b7efa1cce9f09b0a3b30970277 (patch)
treef813abb07d7b003984aa74e3154752b6ffc3ccd5 /docs/app/router.options.ts
parentc7c9ca6f0c8eddf6d34cd40779f3b2d9463f3a46 (diff)
downloadHydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.tar.gz
HydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.zip
✨优化文档
Diffstat (limited to 'docs/app/router.options.ts')
-rw-r--r--docs/app/router.options.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/app/router.options.ts b/docs/app/router.options.ts
new file mode 100644
index 0000000..9380f05
--- /dev/null
+++ b/docs/app/router.options.ts
@@ -0,0 +1,38 @@
+import type { RouterConfig } from '@nuxt/schema'
+// https://router.vuejs.org/api/interfaces/routeroptions.html
+export default <RouterConfig> {
+ scrollBehavior (to, _form, savedPosition) {
+ if (history.state.stop) { return }
+
+ if (history.state.smooth) {
+ return {
+ el: history.state.smooth,
+ behavior: 'smooth'
+ }
+ }
+
+ if (to.hash) {
+ const el = document.querySelector(to.hash) as any
+
+ if (!el) { return }
+
+ const { marginTop } = getComputedStyle(el)
+
+ const marginTopValue = parseInt(marginTop)
+
+ const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
+
+ return {
+ top: offset,
+ behavior: 'smooth'
+ }
+ }
+
+ // Scroll to top of window
+ if (savedPosition) {
+ return savedPosition
+ } else {
+ return { top: 0 }
+ }
+ }
+}