Skip to content

Commit 1033b7a

Browse files
committed
fix: menu init selected
1 parent 7f2d9a7 commit 1033b7a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/crd-seed/layout/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ function BasicLayout({
2323
indexProps,
2424
}) {
2525
const { pathname } = location
26-
// eslint-disable-next-line no-undef
2726
const { user, repo, branch = 'main', language = 'en', menuOpenKeys } = DOCSCONFIG || {}
2827
const [inlineCollapsed, setInlineCollapsed] = useState(isMobile)
2928
const [selectedKey, setSelectedKey] = useState('')
3029
const curOpenKeys = getOpenSubMenuKeys(pathname, menuOpenKeys)
30+
const defaultPath = (routeData.find(data => data.path === '/README')
31+
&& routeData.find(data => data.path === '/README').mdconf
32+
&& routeData.find(data => data.path === '/README').mdconf.abbrlink) || 'README'
3133

3234
useEffect(() => {
3335
if (ifPrerender) {
@@ -50,8 +52,8 @@ function BasicLayout({
5052
if (newPathName.startsWith(`/${repo}`)) {
5153
newPathName = newPathName.slice(`/${repo}`.length, newPathName.length)
5254
}
53-
setSelectedKey(newPathName)
54-
}, location)
55+
setSelectedKey(newPathName || defaultPath)
56+
}, location.pathname)
5557

5658
const scrollToTop = () => {
5759
document.body.scrollTop = 0
@@ -214,11 +216,7 @@ function BasicLayout({
214216
)
215217
}
216218

217-
const carryRepoInProd = ifProd && repo
218219
const renderContent = () => {
219-
const defaultPath = (routeData.find(data => data.path === '/README')
220-
&& routeData.find(data => data.path === '/README').mdconf
221-
&& routeData.find(data => data.path === '/README').mdconf.abbrlink) || 'README'
222220
return (
223221
<div
224222
className={cx(`${styles.content}`, {

0 commit comments

Comments
 (0)