mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-02 07:53:59 +00:00
fix:Menu and breadcrumbs cannot be highlighted with the path.
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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 (
|
||||
<Menu.Item key={item.id}>
|
||||
<Link
|
||||
<Navlink
|
||||
to={addLangPrefix(item.route) || '#'}
|
||||
style={siderFoldN ? { width: 10 } : {}}
|
||||
>
|
||||
{item.icon && <Icon type={item.icon} />}
|
||||
{item.name}
|
||||
</Link>
|
||||
</Navlink>
|
||||
</Menu.Item>
|
||||
)
|
||||
})
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"/dashboard": "/dashboard",
|
||||
"Dark": "Dark",
|
||||
"Dashboard": "Dashboard",
|
||||
"Light": "Light",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"/dashboard": "/zh/dashboard",
|
||||
"Dark": "暗",
|
||||
"Dashboard": "仪表盘",
|
||||
"Light": "明",
|
||||
|
||||
+11
-2
@@ -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 () => <Redirect to="/dashboard" />
|
||||
@withI18n()
|
||||
class Index extends PureComponent {
|
||||
render() {
|
||||
const { i18n } = this.props
|
||||
return <Redirect to={i18n.t`/dashboard`} />
|
||||
}
|
||||
}
|
||||
|
||||
export default Index
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
+1
-2
@@ -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)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user