Files
menav/test/404-fallback.node-test.js
rbetree efd1683e2b feat(router): 支持?page=深链接&错误路由回退
- 导航/子菜单 href 统一为 ?page=<id>[#<slug>],支持复制/新开直达
- 启动时解析 ?page= 并同步导航高亮;子菜单跳转可组合 hash 定位分类
- 输入无效 pageId 时自动纠正 URL 到首页(replaceState,避免“内容回退但地址栏仍错误”)
- 构建生成 dist/404.html:将 /<id>(或 /<repo>/<id>)回跳到 /?page=<id> 并保留 hash
2026-01-07 17:29:48 +08:00

17 lines
791 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const test = require('node:test');
const assert = require('node:assert/strict');
const { generate404Html } = require('../src/generator.js');
test('P1-5404.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 执行回跳');
});