Skip to content
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

bug: ^2.2.4 nav 解析异常! #1815

Closed
ayangweb opened this issue Aug 2, 2023 · 7 comments · Fixed by #1849
Closed

bug: ^2.2.4 nav 解析异常! #1815

ayangweb opened this issue Aug 2, 2023 · 7 comments · Fixed by #1849
Labels
PR Welcome question Further information is requested

Comments

@ayangweb
Copy link
Contributor

ayangweb commented Aug 2, 2023

Versions

  • dumi: ^2.2.4
  • node: v18.16.0
  • npm: 9.5.1
  • OS: MacOS 12.6 M1
  • Browser: Chrome 版本 115.0.5790.114(正式版本) (arm64)

Steps to reproduce

https://github.com/ayangweb/dumi-test

What is Expected?

将上面项目的 dumi 版本改为 ^2.1.22,解析出来的是正常的!

image image

What is actually happening?

^2.2.4 中:

image image image image
@ayangweb ayangweb added the bug Something isn't working label Aug 2, 2023
@ayangweb ayangweb changed the title bug: 最新版 nav 自动解析有问题! bug: ^2.2.4 nav 自动解析有问题! Aug 2, 2023
@ayangweb ayangweb changed the title bug: ^2.2.4 nav 自动解析有问题! bug: ^2.2.4 nav 解析有问题! Aug 2, 2023
@ayangweb ayangweb changed the title bug: ^2.2.4 nav 解析有问题! bug: ^2.2.4 nav 解析异常! Aug 2, 2023
@PeachScript
Copy link
Member

这是符合期望的,因为 2.2.0 开始支持了约定式二级导航,具体可以参考文档说明:https://d.umijs.org/guide/conventional-routing#%E7%BA%A6%E5%AE%9A%E5%BC%8F%E4%BA%8C%E7%BA%A7%E5%AF%BC%E8%88%AA

对于你遇到的问题,如果想恢复到原来的结构,只需要把目录结构从 3 级嵌套调整为 2 级即可,也就是将 docs/guide/install/index.md 重命名为 docs/guide/install.md,英文也是同理

@PeachScript PeachScript added question Further information is requested and removed bug Something isn't working labels Aug 3, 2023
@ayangweb
Copy link
Contributor Author

ayangweb commented Aug 3, 2023

这是符合期望的,因为 2.2.0 开始支持了约定式二级导航,具体可以参考文档说明:https://d.umijs.org/guide/conventional-routing#%E7%BA%A6%E5%AE%9A%E5%BC%8F%E4%BA%8C%E7%BA%A7%E5%AF%BC%E8%88%AA

对于你遇到的问题,如果想恢复到原来的结构,只需要把目录结构从 3 级嵌套调整为 2 级即可,也就是将 docs/guide/install/index.md 重命名为 docs/guide/install.md,英文也是同理

感谢,docs 目录是没有问题了!但是 src 目录如何调整呢?我调整为 test.md 也没有解析成功!

image image image image

@PeachScript
Copy link
Member

PeachScript commented Aug 3, 2023

src 默认是资产文档目录,不会解析嵌套结构,所以保持 src/test/index.md 即可,会生成 /components/test 的路由,这部分逻辑也可以参考上面约定式路由的文档

@ayangweb
Copy link
Contributor Author

ayangweb commented Aug 3, 2023

src 默认是资产文档目录,不会解析嵌套结构,所以保持 src/test/index.md 即可,会生成 /components/test 的路由,这部分逻辑也可以参考上面约定式路由的文档

对,我是这个结构,昨天提 issues 就是这个结构,英文下它生成到 guide 的二级菜单下了!

image image

@ayangweb
Copy link
Contributor Author

ayangweb commented Aug 10, 2023

@PeachScript 大佬啊,新版本的 toc 问题解决了,我这个啥情况啊,再帮我看看呗,英文下组件路由确实跑到指南路由的二级菜单了!

iShot_2023-08-16_23 38 47

@github-actions
Copy link

Hello @ayangweb. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please be sure to fill in the default template in the Pull Request, provide changelog/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @ayangweb,我们完全同意你的提议/反馈,欢迎直接在此仓库创建一个 Pull Request 来解决这个问题。请务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

@PeachScript
Copy link
Member

关键位置:

const [, parentPath, restPath] = link.match(/^(\/[^/]+)([^]+)?$/)!;

原因:这里的 parentPath 应当取 locale 前缀后一级,比如 /en-US/components,目前是把 /en-US 当成一级路由了
解法:link 在做 match 之前先把 locale 前缀去掉,可以用这个 util:
const getLocaleClearPath = (routePath: string, locale: ILocalesConfig[0]) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR Welcome question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants