diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index 8bf5ea3..d15d79e 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -1,9 +1,9 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { Breadcrumb, Icon } from 'antd' -import { Link } from 'react-router-dom' +import Link from 'umi/navlink' import pathToRegexp from 'path-to-regexp' -import { queryArray, addLangPrefix } from 'utils' +import { queryArray, addLangPrefix, pathMatchRegexp, deLangPrefix } from 'utils' import { withI18n } from '@lingui/react' import styles from './Layout.less' @@ -17,7 +17,7 @@ class Bread extends PureComponent { for (let index in menu) { if ( menu[index].route && - pathToRegexp(menu[index].route).exec(location.pathname) + pathMatchRegexp(menu[index].route, location.pathname) ) { current = menu[index] break @@ -49,7 +49,7 @@ class Bread extends PureComponent { let keys = [] let values = pathToRegexp(current.route, keys).exec( - location.pathname.replace('#', '') + deLangPrefix(location.pathname) ) if (keys.length) { keys.forEach((currentValue, index) => { diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index d6f591f..4c63a61 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -1,10 +1,8 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { Menu, Icon } from 'antd' -import { Link } from 'react-router-dom' -import { arrayToTree, queryArray } from 'utils' -import pathToRegexp from 'path-to-regexp' -import { addLangPrefix } from 'utils' +import Navlink from 'umi/navlink' +import { arrayToTree, queryArray, pathMatchRegexp, addLangPrefix } from 'utils' import styles from './Layout.less' const { SubMenu } = Menu @@ -50,13 +48,13 @@ class Menus extends PureComponent { } return ( - {item.icon && } {item.name} - + ) }) @@ -109,7 +107,7 @@ class Menus extends PureComponent { let currentMenu let defaultSelectedKeys for (let item of menu) { - if (item.route && pathToRegexp(item.route).exec(location.pathname)) { + if (item.route && pathMatchRegexp(item.route, location.pathname)) { if (!navOpenKeys.length && item.mpid && !openKeysFlag) changeOpenKeys([String(item.mpid)]) currentMenu = item diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index d9f7efa..01ba622 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1,4 +1,5 @@ { + "/dashboard": "/dashboard", "Dark": "Dark", "Dashboard": "Dashboard", "Light": "Light", diff --git a/src/locales/zh/messages.json b/src/locales/zh/messages.json index 33d446c..17c653f 100644 --- a/src/locales/zh/messages.json +++ b/src/locales/zh/messages.json @@ -1,4 +1,5 @@ { + "/dashboard": "/zh/dashboard", "Dark": "暗", "Dashboard": "仪表盘", "Light": "明", diff --git a/src/pages/index.js b/src/pages/index.js index db47a0e..5cbc165 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,4 +1,13 @@ -import React from 'react' +import React, { PureComponent } from 'react' import Redirect from 'umi/redirect' +import { withI18n } from '@lingui/react' -export default () => +@withI18n() +class Index extends PureComponent { + render() { + const { i18n } = this.props + return + } +} + +export default Index diff --git a/src/pages/login/index.js b/src/pages/login/index.js index 6964132..fb76b6c 100644 --- a/src/pages/login/index.js +++ b/src/pages/login/index.js @@ -5,7 +5,6 @@ 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' diff --git a/src/pages/user/components/List.js b/src/pages/user/components/List.js index 1138b1b..eb6d55e 100644 --- a/src/pages/user/components/List.js +++ b/src/pages/user/components/List.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import { Table, Modal } from 'antd' import classnames from 'classnames' import { DropOption } from 'components' -import { Link } from 'react-router-dom' +import Link from 'umi/link' import AnimTableBody from 'components/DataTable/AnimTableBody' import styles from './List.less' diff --git a/src/utils/index.js b/src/utils/index.js index 1f9bf5d..60a1e78 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -71,7 +71,6 @@ 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 @@ -107,7 +106,7 @@ export const deLangPrefix = curry( * @param {string} pathname Add the language prefix in the pathname. * @return {string} Return the pathname after adding the language prefix. */ -export const addLangPrefix = pathname => { +export function addLangPrefix(pathname) { const prefix = langFromPath(window.location.pathname) return `/${prefix}${deLangPrefix(pathname)}` }