Skip to content

修复 Menu 初始化未高亮的问题 #199

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 3 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ menu: [
docs/书写组件.md,
docs/高阶用法.md,
docs/其它工具.md,
docs/测试
]
## set init open menu keys
# menuOpenKeys:
Expand Down
1 change: 1 addition & 0 deletions docs/测试/测试路由.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* 该页面用来测试未使用 abbrlink 的中文路径。
2 changes: 1 addition & 1 deletion packages/crd-seed/component/NoMatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Footer = () => {
<tr>
<td>
<h1>404</h1>
<div>杯具啊!页面不存在 </div>
<div>你似乎来到了没有知识存在的荒原...</div>
<section>在 github 访问<a href={`https://github.com/${user}/${repo}`}>该项目</a></section>
</td>
</tr>
Expand Down
16 changes: 11 additions & 5 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,24 @@ 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
let newPathName = pathname
// fix https://github.com/MuYunyun/create-react-doc/issues/195
if (newPathName.endsWith('/')) {
newPathName = newPathName.slice(0, newPathName.length - 1)
}
if (newPathName.startsWith(`/${repo}`)) {
newPathName = newPathName.slice(`/${repo}`.length, newPathName.length)
}
setSelectedKey(newPathName)
}, location)

Expand All @@ -52,7 +59,6 @@ function BasicLayout({
window.scrollTo(0, 0)
}
const renderSubMenuItem = (menus) => {
/* eslint-disable */
return (
<>
{menus.map((item, index) => {
Expand Down