From 4d2d615402ddfcd40ff83895df8bf41789f4d237 Mon Sep 17 00:00:00 2001 From: Seyed Sajad Kahani Date: Mon, 11 May 2020 21:33:47 +0430 Subject: [PATCH] fix: change nextTick to onload for anchor scrolling (#1870) * change nextTick to onload for anchor scrolling * fix: handle anchor scrollTo if page already loaded Co-authored-by: Nicolas Giard --- client/themes/default/components/page.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/themes/default/components/page.vue b/client/themes/default/components/page.vue index a84a99bf..90fbe195 100644 --- a/client/themes/default/components/page.vue +++ b/client/themes/default/components/page.vue @@ -460,11 +460,19 @@ export default { }) // -> Handle anchor scrolling - this.$nextTick(() => { - if (window.location.hash && window.location.hash.length > 1) { - this.$vuetify.goTo(window.location.hash, this.scrollOpts) + if (window.location.hash && window.location.hash.length > 1) { + if (document.readyState === 'complete') { + this.$nextTick(() => { + this.$vuetify.goTo(window.location.hash, this.scrollOpts) + }) + } else { + window.addEventListener('load', () => { + this.$vuetify.goTo(window.location.hash, this.scrollOpts) + }) } + } + this.$nextTick(() => { this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => { el.onclick = ev => { ev.preventDefault()