fix:change language after switching language login.

This commit is contained in:
zuiidea
2018-09-15 18:06:24 +08:00
parent 487b39f97c
commit 5f8a298ece
4 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -7,4 +7,4 @@
"Sign in": "Sign in",
"Switch Theme": "Switch Theme",
"Username": "Username"
}
}
+12 -3
View File
@@ -5,6 +5,7 @@ import { Button, Row, Form, Icon, Input } from 'antd'
import router from 'umi/router'
import { GlobalFooter } from 'ant-design-pro'
import { Trans, withI18n } from '@lingui/react'
import { stringify } from 'qs'
import config from 'utils/config'
import styles from './index.less'
@@ -26,7 +27,7 @@ class Login extends PureComponent {
}
render() {
const { loading, form, i18n } = this.props
const { loading, form, i18n, location } = this.props
const { getFieldDecorator } = form
const footerLinks = [
@@ -38,11 +39,19 @@ class Login extends PureComponent {
},
{
key: 'English',
title: <span onClick={() => router.push('/en/login')}>English</span>,
title: (
<span onClick={() => router.push(`/en/login${location.search}`)}>
English
</span>
),
},
{
key: 'Chinese',
title: <span onClick={() => router.push('/zh/login')}>中文</span>,
title: (
<span onClick={() => router.push(`/zh/login${location.search}`)}>
中文
</span>
),
},
]
+2 -2
View File
@@ -1,4 +1,4 @@
import { router } from 'utils'
import { router, pathMatchRegexp } from 'utils'
import { loginUser } from 'api'
export default {
@@ -13,7 +13,7 @@ export default {
if (data.success) {
const { from } = locationQuery
yield put({ type: 'app/query' })
if (from && from !== '/login') {
if (!pathMatchRegexp('/login', from)) {
router.push(from)
} else {
router.push('/dashboard')
+10 -9
View File
@@ -71,6 +71,7 @@ export const langFromPath = curry(
* @return {string} Return the queryed language.
*/
(languages, defaultLanguage, pathname) => {
console.log(pathname)
for (const item of languages) {
if (pathname.startsWith(`/${item}/`)) {
return item
@@ -101,15 +102,15 @@ export const deLangPrefix = curry(
}
)(languages)
export const addLangPrefix = curry(
/**
* Add the language prefix in pathname.
* @param {array} prefix Specify the language you need to add.
* @param {string} pathname Add the language prefix in the pathname.
* @return {string} Return the pathname after adding the language prefix.
*/
(prefix, pathname) => `/${prefix}${deLangPrefix(pathname)}`
)(langFromPath(window.location.pathname))
/**
* Add the language prefix in pathname.
* @param {string} pathname Add the language prefix in the pathname.
* @return {string} Return the pathname after adding the language prefix.
*/
export const addLangPrefix = pathname => {
const prefix = langFromPath(window.location.pathname)
return `/${prefix}${deLangPrefix(pathname)}`
}
const routerAddLangPrefix = params => {
if (isString(params)) {