Skip to content

Instantly share code, notes, and snippets.

@rcobiella
Last active October 15, 2021 14:23
Show Gist options
  • Save rcobiella/6f2b405a42c8bb8e14d42a8242b76d0b to your computer and use it in GitHub Desktop.
Save rcobiella/6f2b405a42c8bb8e14d42a8242b76d0b to your computer and use it in GitHub Desktop.
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