Skip to content

fix: 修复初始化 menu 未被选中的问题。 #196

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

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/crd-seed/layout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'
import * as React from 'react'
import { Switch, Link, Route, Redirect } from 'react-router-dom'
import cx from 'classnames'
import Menu from '../component/Menu'
Expand All @@ -13,6 +13,7 @@ import logo from '../crd.logo.svg'
import styles from './index.less'
import '../style/mobile.less'

const { useState, useEffect } = React
const SubMenu = Menu.SubMenu

function BasicLayout({
Expand All @@ -31,18 +32,19 @@ function BasicLayout({
useEffect(() => {
if (ifPrerender) {
scrollToTop()
// eslint-disable-next-line no-undef
INJECT?.inject?.()
}
}, [])

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

useEffect(() => {
const newPathName = location.pathname
const { pathname } = location
const newPathName = pathname.endsWith('/')
? pathname.slice(0, pathname.length - 1)
: pathname
setSelectedKey(newPathName)
}, location)

Expand Down