123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- export default function(to, from, savedPosition) {
-
-
- let position = false;
-
- const reg = /\/category/;
- if (reg.test(to.path) && reg.test(from.path) || to.path !== from.path) {
-
- position = { x: 0, y: 0 };
- } else if (savedPosition) {
- position = savedPosition;
- }
- if (to.hash) {
- let hash = to.hash;
-
- if (
- typeof window.CSS !== 'undefined' &&
- typeof window.CSS.escape !== 'undefined')
- {
- hash = '#' + window.CSS.escape(hash.substr(1));
- }
- try {
- if (document.querySelector(hash)) {
-
- position = { selector: hash };
- } else {
-
- return new Promise((resolve) => {
- window.$nuxt.$once('triggerScroll', () => {
- position = { selector: hash };
- resolve(position);
- });
- });
- }
- } catch (e) {
- console.warn(
- 'Failed to save scroll position. Please add CSS.escape() polyfill (https://github.com/mathiasbynens/CSS.escape).'
- );
- }
- return position;
- } else {
- return position;
- }
- }
|