feat(router): 支持?page=深链接&错误路由回退
- 导航/子菜单 href 统一为 ?page=<id>[#<slug>],支持复制/新开直达 - 启动时解析 ?page= 并同步导航高亮;子菜单跳转可组合 hash 定位分类 - 输入无效 pageId 时自动纠正 URL 到首页(replaceState,避免“内容回退但地址栏仍错误”) - 构建生成 dist/404.html:将 /<id>(或 /<repo>/<id>)回跳到 /?page=<id> 并保留 hash
This commit is contained in:
16
test/404-fallback.node-test.js
Normal file
16
test/404-fallback.node-test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { generate404Html } = require('../src/generator.js');
|
||||
|
||||
test('P1-5:404.html 回跳应将 /<id> 转为 ?page=<id>(并支持仓库前缀)', () => {
|
||||
const html = generate404Html({ site: { title: 'Test Site' } });
|
||||
|
||||
assert.ok(typeof html === 'string' && html.length > 0);
|
||||
assert.ok(html.includes('?page='), '应包含 ?page= 形态');
|
||||
assert.ok(html.includes('encodeURIComponent(pageId)'), '应对 pageId 做 URL 编码');
|
||||
assert.ok(html.includes('segments.length === 1'), '应支持用户站点 /<id>');
|
||||
assert.ok(html.includes('segments.length === 2'), '应支持仓库站点 /<repo>/<id>');
|
||||
assert.ok(html.includes('l.replace(target)'), '应使用 location.replace 执行回跳');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user