|
|
@@ -6,14 +6,21 @@ import { convertTitleCase } from '@/utils/helpers'
|
|
6
|
6
|
const router = createRouter({
|
|
7
|
7
|
history: createWebHistory(),
|
|
8
|
8
|
routes,
|
|
|
9
|
+ scrollBehavior(to, from, savedPosition) {
|
|
|
10
|
+ let pos = { x: 0, y: 0 }
|
|
|
11
|
+ if (savedPosition) {
|
|
|
12
|
+ pos = savedPosition
|
|
|
13
|
+ }
|
|
|
14
|
+ if (to.hash) {
|
|
|
15
|
+ pos = { el: to.hash }
|
|
|
16
|
+ }
|
|
|
17
|
+ return pos
|
|
|
18
|
+ }
|
|
9
|
19
|
})
|
|
10
|
20
|
|
|
11
|
21
|
router.beforeEach((to, from, next) => {
|
|
12
|
22
|
document.title = 'Craft in America'
|
|
13
|
23
|
|
|
14
|
|
- // Scroll to top
|
|
15
|
|
- window.scrollTo(0, 0)
|
|
16
|
|
-
|
|
17
|
24
|
// Append list type
|
|
18
|
25
|
if (to.path.split('/').length > 1 && to.path.split('/')[1]) {
|
|
19
|
26
|
const path = convertTitleCase(to.path.split('/')[1])
|
|
|
@@ -24,17 +31,9 @@ router.beforeEach((to, from, next) => {
|
|
24
|
31
|
document.title = `${document.title} - ${to.path.split('/')[2]}`
|
|
25
|
32
|
}
|
|
26
|
33
|
|
|
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
|
34
|
// Regular links
|
|
35
|
|
- else {
|
|
36
|
|
- next()
|
|
37
|
|
- }
|
|
|
35
|
+ next()
|
|
|
36
|
+
|
|
38
|
37
|
})
|
|
39
|
38
|
|
|
40
|
39
|
export default router
|