Skip to content

fix(notion): 修复菜单跳转 Category Mapping Page 404 - #4344

Merged
tangly1024 merged 1 commit into
notionnext-org:mainfrom
kforris:fix/4336-menu-category-mapping
Jul 31, 2026
Merged

fix(notion): 修复菜单跳转 Category Mapping Page 404#4344
tangly1024 merged 1 commit into
notionnext-org:mainfrom
kforris:fix/4336-menu-category-mapping

Conversation

@kforris

@kforris kforris commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

已知问题

启用 POST_URL_PREFIX_MAPPING_CATEGORY 后,Page 会在站点数据生成阶段得到带分类与日期前缀的最终路由;但指向该 Page 原始 Slug 的 Menu / SubMenu 仍保留旧路径,因此点击后进入 404。

Fixes #4336

解决方案

  1. 在 Page 应用 Category Mapping 前保留其原始 Slug。
  2. 生成自定义菜单时,用原始 Slug 将 Menu / SubMenu 与已发布 Page 做精确匹配。
  3. 仅在匹配唯一时,把菜单链接更新为 Page 的最终 href,因此会同时继承分类前缀、日期前缀和伪静态 .html
  4. 外链、未匹配菜单以及原始 Slug 冲突的页面保持原行为,不做猜测。

改动收益

  • Menu 与 SubMenu 会跟随目标 Page 的最终路由,不再因 Category Mapping 进入 404。
  • 修复位于共享数据层,所有主题都能获得一致结果。
  • 不新增配置、不改变 Page 路由生成规则,也不影响外部链接。

具体改动

  1. lib/db/SiteDataApi.js
    • 在调整 Page 路由前保存原始 Slug;
    • 使用提取后的菜单生成函数。
  2. lib/db/notion/getCustomMenu.js
    • 封装既有菜单层级逻辑;
    • 增加“原始 Page Slug → 最终 href”的唯一匹配。
  3. __tests__/lib/db/SiteDataApi.customMenu.test.js
    • 覆盖 Menu、SubMenu、伪静态后缀、外链、未匹配与重复 Slug 场景。

风险与兼容性评估

  • 风险等级:中低。
  • 仅匹配 Published Page,且要求原始 Slug 唯一;有歧义时保留菜单原链接。
  • 现有菜单层级、showtarget 和外链行为不变。
  • 无依赖升级、数据迁移或配置默认值变化。

测试确认

  • yarn test __tests__/lib/db/SiteDataApi.customMenu.test.js __tests__/lib/db/notion/getPageProperties.test.js --runInBand(2 suites / 4 tests)
  • yarn test --runInBand(36 suites / 197 tests)
  • yarn type-check
  • yarn lint(退出码 0;仅有 main 已存在的 warnings)
  • yarn build(61 个静态页面生成完成)
  • yarn deps:check-lockfile
  • git diff --check

用户文档(docs/user-guide/ / docs/developer/

  • 不适用:本次恢复 Menu / SubMenu 指向 Page 的既有语义,不新增站长配置、环境变量或部署步骤。

@kforris
kforris requested a review from tangly1024 as a code owner July 29, 2026 21:06
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@kforris is attempting to deploy a commit to the tangly1024's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy Preview for notionnext-netlify ready!

Name Link
🔨 Latest commit 3177661
🔍 Latest deploy log https://app.netlify.com/projects/notionnext-netlify/deploys/6a6a6b60a486d100083f0ff5
😎 Deploy Preview https://deploy-preview-4344--notionnext-netlify.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
notion-next-preview Ready Ready Preview Jul 31, 2026 7:42am

@tangly1024
tangly1024 merged commit d87a67d into notionnext-org:main Jul 31, 2026
11 of 13 checks passed
@tangly1024

Copy link
Copy Markdown
Collaborator

这版修复很干净:把菜单来源 slug 和最终页面 href 解耦,避免了 Menu / SubMenu 在 Category Mapping 场景下继续指向旧路径。

测试覆盖也到位,尤其是重复 source slug 的歧义回退,合并后应该能稳定收住这类回归。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu / SubMenu 跳转到使用 Category Mapping 的 Page 时进入 404

2 participants