diff --git a/docs/gridsome.client.js b/docs/gridsome.client.js new file mode 100644 index 000000000..65d2f3f2f --- /dev/null +++ b/docs/gridsome.client.js @@ -0,0 +1,15 @@ +export default function (Vue, options, context) { + + context.router.afterEach(to => { + if (to.hash) { + setTimeout(() => { + const element = document.getElementById(to.hash.substr(1)) + const top = element.offsetTop + const offset = parseFloat(getComputedStyle(element).scrollMarginTop) + + window.scrollTo(0, top - offset) + }, 0) + } + }) + +} diff --git a/docs/src/main.js b/docs/src/main.js index 68c8b9681..99476dbe8 100644 --- a/docs/src/main.js +++ b/docs/src/main.js @@ -5,30 +5,9 @@ import 'prismjs/components/prism-scss.js' import PortalVue from 'portal-vue' import App from '~/layouts/App' -export default function (Vue, { router }) { +export default function (Vue) { Vue.use(PortalVue) Vue.component('Layout', App) Vue.component('Demo', () => import(/* webpackChunkName: "demo" */ '~/components/Demo')) Vue.component('LiveDemo', () => import(/* webpackChunkName: "live-demo" */ '~/components/LiveDemo')) - - router.options.scrollBehavior = async (to, from, savedPosition) => { - if (to.hash) { - const elem = document.querySelector(to.hash) - - if (elem) { - const offset = parseFloat(getComputedStyle(elem).scrollMarginTop) - return { - selector: to.hash, - offset: { y: offset }, - } - } - } - - if (savedPosition) { - return savedPosition - } - - return { x: 0, y: 0 } - } - }