From e8507341f61b530eae23ab4e859d71b0e11368af Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 24 Jul 2016 17:32:02 +0800 Subject: [PATCH] Fix site hash link error --- site/theme/template/Content/MainContent.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index 98554ea079..88cc53cc92 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -6,6 +6,7 @@ import ComponentDoc from './ComponentDoc'; import * as utils from '../utils'; import config from '../../'; const SubMenu = Menu.SubMenu; +let firstMounted = false; export default class MainContent extends React.Component { static contextTypes = { @@ -16,11 +17,12 @@ export default class MainContent extends React.Component { if (!location.hash) { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; - } else { + } else if (!firstMounted) { this.timer = setTimeout(() => { - document.getElementById(location.hash.replace('#', '')).scrollIntoView(); + document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView(); }, 10); } + firstMounted = true; } componentWillUnmount() {