接入移动壳受控路由导航

移动 HostBridge 声明 navigation.openNativePage 并限制为同源 H5 route

Expo WebView 将受控导航请求切换为新的 WebView URL

补充移动壳 HostBridge 与导航解析测试和配置守卫

更新宿主壳方案、统一协议和团队共享决策记录
This commit is contained in:
2026-06-17 22:15:31 +08:00
parent 02a475d652
commit 080ebaedfd
9 changed files with 249 additions and 6 deletions
@@ -1,6 +1,9 @@
import { describe, expect, test } from 'vitest';
import { shouldOpenInMobileShellWebView } from './mobileShellNavigation';
import {
resolveMobileShellWebViewUrl,
shouldOpenInMobileShellWebView,
} from './mobileShellNavigation';
describe('shouldOpenInMobileShellWebView', () => {
test('只允许主站同源页面留在移动壳 WebView 内', () => {
@@ -33,4 +36,24 @@ describe('shouldOpenInMobileShellWebView', () => {
false,
);
});
test('HostBridge 主动导航只解析同源网页目标', () => {
const allowedOrigin = 'https://app.genarrative.world';
expect(
resolveMobileShellWebViewUrl('/works/detail?work=PZ-1', allowedOrigin),
).toBe('https://app.genarrative.world/works/detail?work=PZ-1');
expect(
resolveMobileShellWebViewUrl(
'https://app.genarrative.world/creation/puzzle#draft',
allowedOrigin,
),
).toBe('https://app.genarrative.world/creation/puzzle#draft');
expect(
resolveMobileShellWebViewUrl('https://example.com/', allowedOrigin),
).toBeNull();
expect(
resolveMobileShellWebViewUrl('about:blank', allowedOrigin),
).toBeNull();
});
});