From 4cf46e250e0e9e0b84f0fcb3ba69addb054c43aa Mon Sep 17 00:00:00 2001 From: bendtherules Date: Mon, 26 Oct 2020 12:12:05 +0530 Subject: [PATCH] handleScrollRestoration - Add script to head This will set history.scrollRestoration to "manual" on page start, if hash starts with "link-" --- docusaurus.config.js | 6 ++++++ static/scripts/handleScrollRestoration.js | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 static/scripts/handleScrollRestoration.js diff --git a/docusaurus.config.js b/docusaurus.config.js index 69faacd..1c9b7a7 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -102,4 +102,10 @@ module.exports = { }, ], ], + scripts: [ + { + src: + '/scripts/handleScrollRestoration.js', + }, + ] }; diff --git a/static/scripts/handleScrollRestoration.js b/static/scripts/handleScrollRestoration.js new file mode 100644 index 0000000..bd93e7c --- /dev/null +++ b/static/scripts/handleScrollRestoration.js @@ -0,0 +1,8 @@ +var hash = window.location.hash; +var hashName = hash.substring(1, hash.length); + +if (hashName.startsWith("link-")) { + if ("scrollRestoration" in history) { + history.scrollRestoration = "manual"; + } +}