Skip to content

Commit

Permalink
router scroll behavior (kodilan-com#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
berkansivri authored and fatihacet committed Jan 20, 2020
1 parent 4c2104f commit 5fea7bc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const router = new Router({
meta: {
period: period.type,
hasBanner: true,
scroll: true,
},
})),
},
Expand Down Expand Up @@ -102,6 +103,15 @@ const router = new Router({
},
],
scrollBehavior(to, from, savedPosition) {
if (to.meta.scroll) {
const element = document.querySelector('.router-link-exact-active');
if (element) {
element.scrollIntoView({ behavior: 'smooth' });

return {};
}
}

return savedPosition || { x: 0, y: 0 };
},
});
Expand Down

0 comments on commit 5fea7bc

Please sign in to comment.