From 1c87f36dd4801fc4cac86bfe9eef72dcbf8a2f59 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 13 Jul 2016 16:06:07 +0800 Subject: [PATCH] Fix chrome hash link --- site/theme/template/Content/MainContent.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index f54d4ce64..77b738bd7 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -17,10 +17,16 @@ export default class MainContent extends React.Component { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; } else { - location.hash = location.hash; + this.timer = setTimeout(() => { + document.getElementById(location.hash.replace('#', '')).scrollIntoView(); + }, 10); } } + componentWillUnmount() { + clearTimeout(this.timer); + } + shouldComponentUpdate(nextProps) { const pathname = this.props.location.pathname; return pathname !== nextProps.location.pathname ||