Browse Source

improve smooth scroll

Yuki Takei 4 years ago
parent
commit
41fb190fe6
1 changed files with 3 additions and 1 deletions
  1. 3 1
      packages/app/src/client/services/NavigationContainer.js

+ 3 - 1
packages/app/src/client/services/NavigationContainer.js

@@ -131,10 +131,12 @@ export default class NavigationContainer extends Container {
    */
   addSmoothScrollEvent(elements = {}) {
     elements.forEach(link => link.addEventListener('click', (e) => {
+      // modify location.hash without scroll
       e.preventDefault();
+      window.history.pushState({}, '', link.href);
 
+      // smooth scroll
       const href = link.getAttribute('href').replace('#', '');
-      window.location.hash = href;
       const targetDom = document.getElementById(href);
       this.smoothScrollIntoView(targetDom, WIKI_HEADER_LINK);
     }));