Files
Genarrative/apps/mobile-shell/src/shell/webViewHistory.ts
T
kdletters 0ad56a878f 移动壳补齐 H5 返回栈追踪
为 Expo WebView 注入当前文档 history 状态追踪脚本

让移动壳合成 H5 路由栈和 WebView 原生返回状态

让 Android 返回键优先回退 H5 当前文档路由

补充移动壳解析测试、注入脚本测试和配置门禁

更新原生壳方案文档和共享决策
2026-06-18 22:20:58 +08:00

32 lines
665 B
TypeScript

export type MobileWebViewHistoryStateMessage = {
canGoBack: boolean;
};
export function parseMobileWebViewHistoryStateMessage(
rawMessage: string,
): MobileWebViewHistoryStateMessage | null {
try {
const value = JSON.parse(rawMessage) as unknown;
if (!value || typeof value !== 'object') {
return null;
}
const candidate = value as {
type?: unknown;
canGoBack?: unknown;
};
if (
candidate.type !== 'genarrative.mobile.historyState' ||
typeof candidate.canGoBack !== 'boolean'
) {
return null;
}
return {
canGoBack: candidate.canGoBack,
};
} catch {
return null;
}
}