Last active
October 15, 2021 14:23
-
-
Save rcobiella/6f2b405a42c8bb8e14d42a8242b76d0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (to, from, savedPosition) { | |
const nuxt = window["<%= globals.nuxt %>"]; | |
if (to.path === from.path) { | |
return; | |
} | |
if (to.hash) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve({ | |
selector: to.hash, | |
}); | |
}, 500); | |
}); | |
} | |
const position = savedPosition || { x: 0, y: 0 }; | |
return new Promise((resolve, reject) => { | |
nuxt.$root.$once("triggerScroll", () => { | |
nuxt.$nextTick(() => { | |
resolve(position); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment