fix(client): fallback to directory route when .html route does not exist - #1720
Open
MEMZ-CHROER wants to merge 2 commits into
Open
fix(client): fallback to directory route when .html route does not exist#1720MEMZ-CHROER wants to merge 2 commits into
MEMZ-CHROER wants to merge 2 commits into
Conversation
When resolving a clean URL (no trailing slash) like /foo, the normalizeRoutePath converts it to /foo.html. If the page is a directory page (foo/README.md → /foo/), the /foo.html route does not exist in the routes table, causing a 404 or an infinite redirect loop when deployed behind static hosts that normalize URLs (e.g. Vercel). Fallback to the directory route /foo/ when the normalized .html route does not exist, so that clean URLs can resolve to directory pages correctly. Fix #3239
Author
本地验证记录(首次贡献者,CI 尚未放行,先在此附上)已在本机完成全部 CONTRIBUTING.md 要求的检查:
补丁逻辑( 新增测试覆盖:
关联 issue:#1719 |
Author
与 #1538 的关系说明已知 @Mister-Hope 的 #1538(
完全支持 #1538 的长远方向。 |
Refine the directory fallback logic to only trigger when the raw path has no extension. The same-named file route (e.g. /foo.html from foo.md) is prioritized over the directory route (/foo/), so /foo resolves to /foo.html when foo.md exists, and only falls back to /foo/ when it does not. This avoids conflating foo.md with foo/README.md.
Author
|
更新:已按 @Mister-Hope 的反馈把回退逻辑收紧为安全回退,消除了"混淆 改动( 测试新增:同名文件优先 + 纯目录兜底两个场景(669 个测试全过)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复 clean URL(无后缀)访问目录页时被转成不存在的
.html导致 404 / 无限重定向循环的问题。问题
目录式内容(
foo/README.md→ 路由/foo/)下,客户端访问/foo(clean URL):部署在会规范化 URL 的静态托管(Vercel 等)时,托管层把
/foo.html301 回目录 → 浏览器去斜杠 → 无限重定向循环。修复
packages/client/src/router/resolveRoutePath.ts:当规范化的.html路由不存在时,回退匹配目录路由(/foo.html→/foo/),前提是目录路由真实存在(避免误伤真正的.html页面)。测试
新增
packages/client/tests/router/resolveRoutePath.spec.ts,覆盖:/foo→/foo/).html页面不受影响(/foo/bar.html→/foo/bar.html)/not-exist→/not-exist.html)验证
Closes #1719