mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +08:00
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:
parent
917ec5606e
commit
a5f136f334
@ -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)),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user