Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ definePageMeta({
'/package/code/:packageName/v/:version/:filePath(.*)?',
// '/code/@:org?/:packageName/v/:version/:filePath(.*)?',
],
scrollMargin: 160,
})

const route = useRoute('code')
Expand Down
1 change: 1 addition & 0 deletions app/pages/package-docs/[...path].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ definePageMeta({
name: 'docs',
path: '/package-docs/:path+',
alias: ['/package/docs/:path+', '/docs/:path+'],
scrollMargin: 180,
})

const route = useRoute('docs')
Expand Down
1 change: 1 addition & 0 deletions app/pages/package/[[org]]/[name]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// stub page to help with paths
definePageMeta({
name: 'package',
scrollMargin: 150,
})
</script>

Expand Down
9 changes: 7 additions & 2 deletions app/router.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import type { RouterConfig } from 'nuxt/schema'
export default {
scrollBehavior(to, _from, savedPosition) {
// If the browser has a saved position (e.g. back/forward navigation), restore it

if (savedPosition) {
return savedPosition
}

// If navigating to a hash anchor, scroll to it
if (to.hash) {
return { el: to.hash, behavior: 'smooth' }
const { scrollMargin } = to.meta
return {
el: to.hash,
behavior: 'smooth',
top: typeof scrollMargin == 'number' ? scrollMargin : 70,
}
}

// Otherwise, scroll to the top of the page
Expand Down
12 changes: 12 additions & 0 deletions app/types/routeMeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import '#app'
import '#vue-router'

declare module '#app' {
interface PageMeta {
/**
* top margin in pixels for scrolling to an element
* @default 70
*/
scrollMargin?: number
}
}
Loading