antD首页从英文切换到中文时,replace导致链接错误 (#5050)

首页从英文转到中文,点击header上的“中文”时,链接会跳到 https://ant.design/index-cn/ant.design/ (Chrome)或者 https://index-cn/ant.design/ (Safari)

bug来自handleLangChange函数下,最后对location.href.replace操作时出错,原因来自replace匹配到location.href的第一个/
('https://ant.design/').replace('/', '/index-cn') 的运行结果是 https:/index-cn/ant.design/ 

为了避免replace匹配到location.href的第一个/,我建议的方案是使用 location.origin + location.pathname.replace

最后,感谢antD团队开发出那么棒的UI~
This commit is contained in:
YuyingWu 2017-02-26 00:23:04 +08:00 committed by 偏右
parent 917ec5606e
commit a5f136f334

View File

@ -87,7 +87,7 @@ export default class Header extends React.Component {
if (utils.isLocalStorageNameSupported()) {
localStorage.setItem('locale', utils.isZhCN(pathname) ? 'en-US' : 'zh-CN');
}
location.href = location.href.replace(
location.href = location.origin + location.pathname.replace(
location.pathname,
utils.getLocalizedPathname(pathname, !utils.isZhCN(pathname)),
);