File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change
1
+ import type { RouterConfig } from '@nuxt/schema'
2
+
3
+ // https://router.vuejs.org/api/#routeroptions
4
+ export default < RouterConfig > {
5
+ scrollBehavior : ( to , from , savedPosition ) => {
6
+ // scroll to hash, useful for using to="#some-id" in NuxtLink
7
+ // ex: <NuxtLink to="#top"> To Top </ NuxtLink>
8
+ if ( to . hash ) {
9
+ // console.log('to.hash: ', to.hash)
10
+ return {
11
+ el : to . hash ,
12
+ top : 100 ,
13
+ behavior : 'smooth' ,
14
+ }
15
+ }
16
+
17
+ // The remainder is optional but maybe useful as well
18
+
19
+ // if link is to same page, scroll to top with smooth behavior
20
+ if ( to === from ) {
21
+ return {
22
+ left : 0 ,
23
+ top : 0 ,
24
+ behavior : 'smooth' ,
25
+ }
26
+ }
27
+
28
+ // this will use saved scroll position on browser forward/back navigation
29
+ return new Promise ( ( resolve ) => {
30
+ setTimeout ( ( ) => {
31
+ resolve ( {
32
+ left : savedPosition ?. left || 0 ,
33
+ top : savedPosition ?. top || 0 ,
34
+ } )
35
+ } , 500 )
36
+ } )
37
+ } ,
38
+ }
Original file line number Diff line number Diff line change 2
2
const { path } = useRoute ()
3
3
const articles = await queryContent (path ).findOne ()
4
4
5
- const links = articles .body .toc .links
5
+ const links = articles ? .body ? .toc ? .links || []
6
6
</script >
7
7
8
8
<template >
You can’t perform that action at this time.
0 commit comments