Skip to content

Commit fee697f

Browse files
committed
fix: init menu selected
1 parent a106448 commit fee697f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/crd-seed/layout/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react'
1+
import * as React from 'react'
22
import { Switch, Link, Route, Redirect } from 'react-router-dom'
33
import cx from 'classnames'
44
import Menu from '../component/Menu'
@@ -13,6 +13,7 @@ import logo from '../crd.logo.svg'
1313
import styles from './index.less'
1414
import '../style/mobile.less'
1515

16+
const { useState, useEffect } = React
1617
const SubMenu = Menu.SubMenu
1718

1819
function BasicLayout({
@@ -31,18 +32,19 @@ function BasicLayout({
3132
useEffect(() => {
3233
if (ifPrerender) {
3334
scrollToTop()
34-
// eslint-disable-next-line no-undef
3535
INJECT?.inject?.()
3636
}
3737
}, [])
3838

3939
useEffect(() => {
40-
// eslint-disable-next-line no-undef
4140
INJECT?.injectWithPathname?.(pathname)
4241
}, [pathname])
4342

4443
useEffect(() => {
45-
const newPathName = location.pathname
44+
const { pathname } = location
45+
const newPathName = pathname.endsWith('/')
46+
? pathname.slice(0, pathname.length - 1)
47+
: pathname
4648
setSelectedKey(newPathName)
4749
}, location)
4850

0 commit comments

Comments
 (0)