Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 25, 2017

Conversation

Projects
None yet
5 participants
@YuyingWu
Copy link
Contributor

commented Feb 25, 2017

首页从英文转到中文,点击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

btw,我clone下来后,执行npm run start或npm run site时有个模块在报错,所以我没有办法在本地测试运行,建议在merge前再测测。我修复的方法是执行compile后,把.js涉及的函数写成demo测试的,不过解决逻辑应该没错。

最后,感谢antD团队开发出那么棒的UI~

First of all, thanks for your contribution! :-)

Please makes sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow antd's code convention.
  • Run npm run lint and fix those errors before submitting in order to keep consistent code style.
  • Rebase before creating a PR to keep commit history clear.
  • Add some descriptions and refer relative issues for you PR.
antD首页从英文切换到中文时,replace导致链接错误
首页从英文转到中文,点击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~
@mention-bot

This comment has been minimized.

Copy link

commented Feb 25, 2017

@YuyingWu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @benjycui, @afc163 and @pinggod to be potential reviewers.

@coveralls

This comment has been minimized.

Copy link

commented Feb 25, 2017

Coverage Status

Coverage remained the same at 81.873% when pulling 0c6da21 on YuyingWu:master into 917ec56 on ant-design:master.

@afc163 afc163 merged commit a5f136f into ant-design:master Feb 25, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
coverage/coveralls Coverage remained the same at 81.873%
Details
@afc163

This comment has been minimized.

Copy link
Member

commented Feb 25, 2017

Thx! 😅

@@ -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(

This comment has been minimized.

Copy link
@benjycui

benjycui Feb 26, 2017

Contributor

这样 hash 和 queryString 就丢失了。。

This comment has been minimized.

Copy link
@YuyingWu

YuyingWu Feb 26, 2017

Author Contributor

@benjycui 嗯,我想到另外一个方案,先把href的protocol(http://)字段截取,replace后再补回来,这次我在本地带hash和query测过,可用。我再发一个PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.