소스 검색

:sparkles: jumplink router guard

tags/0.9.0
j 4 년 전
부모
커밋
38571fb7d7
1개의 변경된 파일13개의 추가작업 그리고 2개의 파일을 삭제
  1. 13
    2
      vue-theme/src/router/index.js

+ 13
- 2
vue-theme/src/router/index.js 파일 보기

20
         document.title = `${document.title} - ${path}`
20
         document.title = `${document.title} - ${path}`
21
     }
21
     }
22
     // Append slugs and sort titles
22
     // Append slugs and sort titles
23
-    if (to.path.split('/')[2])
23
+    if (to.path.split('/')[2]) {
24
         document.title = `${document.title} - ${to.path.split('/')[2]}`
24
         document.title = `${document.title} - ${to.path.split('/')[2]}`
25
+    }
25
 
26
 
26
-    next()
27
+    // Jump link intercept
28
+    if (to.hash) {
29
+        console.log('jump to:', to.hash)
30
+        const el = document.querySelector(to.hash)
31
+        const barHeight = 50
32
+        window.scrollTo(0, el.offsetTop - barHeight)
33
+    }
34
+    // Regular links
35
+    else {
36
+        next()
37
+    }
27
 })
38
 })
28
 
39
 
29
 export default router
40
 export default router

Loading…
취소
저장