Skip to content

Commit d75c225

Browse files
committed
fix: menu init open
1 parent 3bb1ba2 commit d75c225

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

packages/crd-seed/layout/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ function BasicLayout({
2323
indexProps,
2424
}) {
2525
console.log('menuSource', menuSource)
26-
console.log('routeData', routeData)
2726

2827
const { pathname } = location
2928
console.log('location', location)
3029
const { user, repo, branch = 'main', language = 'en', menuOpenKeys } = DOCSCONFIG || {}
3130
const [inlineCollapsed, setInlineCollapsed] = useState(isMobile)
3231
const [selectedKey, setSelectedKey] = useState('')
33-
// console.log()
3432
const curOpenKeys = getOpenSubMenuKeys({
3533
pathname,
3634
menuSource,
@@ -142,9 +140,9 @@ function BasicLayout({
142140
onSelect={(keyValue) => {
143141
setSelectedKey(keyValue)
144142
}}
145-
// defaultOpenKeys={curOpenKeys}
143+
defaultOpenKeys={curOpenKeys}
146144
// todo: smart to fill defaultOpenKeys
147-
defaultOpenKeys={['/docs/主题']}
145+
// defaultOpenKeys={['/docs/主题']}
148146
>
149147
{renderSubMenuItem(menus || [])}
150148
</Menu>

packages/crd-seed/layout/utils.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@ function getOpenSubMenuKeys({
1313
menuOpenKeys
1414
}) {
1515
const result = []
16-
getOpenSubMenuKeysForAbbrLink(menuSource, pathname, result)
16+
getOpenSubMenuKeysForAbbrLink(
17+
menuSource,
18+
decodeURI(pathname),
19+
result
20+
)
21+
1722
/**
1823
* logic for not abbrLink
1924
* there is no pick item if the length of pathnameSplit is less than or equal to 2.
2025
* eg: /README => ["", "README"]
2126
*/
22-
const pathnameSplit = pathname.split('/')
23-
if (pathnameSplit.length <= 2) return result
24-
let recordValue = ''
25-
for (let i = 1; i < pathnameSplit.length - 1; i++) {
26-
recordValue += `/${pathnameSplit[i]}`
27-
result.push(recordValue)
28-
}
27+
// const pathnameSplit = pathname.split('/')
28+
// if (pathnameSplit.length <= 2) return result
29+
// let recordValue = ''
30+
// for (let i = 1; i < pathnameSplit.length - 1; i++) {
31+
// recordValue += `/${pathnameSplit[i]}`
32+
// result.push(recordValue)
33+
// }
2934

3035
/** default open menu from config.yml */
3136
if (menuOpenKeys) {
@@ -44,7 +49,10 @@ function getOpenSubMenuKeysForAbbrLink(source, pathname, result) {
4449
if (ifFind) return true
4550
result.pop()
4651
} else {
47-
if (pathname.indexOf(mdconf.abbrlink) > -1) {
52+
if (
53+
pathname.indexOf(mdconf.abbrlink) > -1
54+
|| (pathname === source[i].routePath)
55+
) {
4856
return true
4957
}
5058
}

0 commit comments

Comments
 (0)