Files
Genarrative/src/routing/runtimeNotFoundRecovery.ts
kdletters 54968701f0
Some checks failed
CI / verify (push) Has been cancelled
fix public work detail not found recovery
2026-05-11 19:52:25 +08:00

55 lines
1.6 KiB
TypeScript

export type RuntimeNotFoundRecoveryAction = {
nextStage: 'platform';
nextPath: '/';
shouldAlert: true;
};
/**
* 中文注释:直接打开 /runtime/<玩法>?work=<作品号> 时,如果作品不存在,
* 弹窗关闭后必须回到首页,避免继续停留在没有运行态数据的空白页面。
*/
export function resolveRuntimeNotFoundRecoveryAction(
pathname: string,
): RuntimeNotFoundRecoveryAction | null {
const normalizedPath = pathname.trim().toLowerCase().replace(/\/+$/u, '');
if (
normalizedPath === '/runtime/puzzle' ||
normalizedPath === '/runtime/match3d' ||
normalizedPath === '/runtime/big-fish' ||
normalizedPath === '/runtime/square-hole' ||
normalizedPath === '/runtime/visual-novel'
) {
return {
nextStage: 'platform',
nextPath: '/',
shouldAlert: true,
};
}
return null;
}
/**
* 中文注释:公开作品详情页和运行态深链都可能在作品被删除或下架后失效。
* 这类入口没有上一层可回退的详情数据,确认提示后统一回首页,避免空详情页白屏。
*/
export function resolveWorkNotFoundRecoveryAction(
pathname: string,
): RuntimeNotFoundRecoveryAction | null {
const normalizedPath = pathname.trim().toLowerCase().replace(/\/+$/u, '');
if (
normalizedPath === '/works/detail' ||
normalizedPath === '/gallery/puzzle/detail' ||
normalizedPath === '/gallery/visual-novel/detail'
) {
return {
nextStage: 'platform',
nextPath: '/',
shouldAlert: true,
};
}
return resolveRuntimeNotFoundRecoveryAction(pathname);
}