Skip to content

Commit

Permalink
feat(scroll-top): fix scroll top on page changes.. same fix as nuxt.com
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Dec 5, 2022
1 parent 71218dd commit f492439
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
19 changes: 12 additions & 7 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default defineAppConfig({
}
})

interface IconLink {
href: string
icon: string
label?: string
}

declare module '@nuxt/schema' {
interface AppConfigInput {
docus?: {
Expand All @@ -100,6 +106,7 @@ declare module '@nuxt/schema' {
aside?: {
level: number
exclude?: string[]
collapsed?: boolean
},
header?: {
title?: string,
Expand All @@ -108,15 +115,13 @@ declare module '@nuxt/schema' {
exclude?: string[]
},
footer?: {
credits?: boolean
credits?: boolean | {
icon: string
text: string
href: string
}
iconLinks?: IconLink[]
}
}
}
}

interface IconLink {
href: string
icon: string
label?: string
}
18 changes: 17 additions & 1 deletion app/router.options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig> {
scrollBehavior (to) {
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

Expand All @@ -18,5 +27,12 @@ export default <RouterConfig> {
behavior: 'smooth'
}
}

// Scroll to top of window
if (savedPosition) {
return savedPosition
} else {
return { top: 0 }
}
}
}

1 comment on commit f492439

@vercel
Copy link

@vercel vercel bot commented on f492439 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.