深度链接

配置 custom scheme、Universal Links、App Links 和可路由目标。

深度链接有两个入口:app.config.ts 生成的 variant 专属 custom URL scheme,以及设置 EXPO_PUBLIC_LINKING_DOMAIN 后启用的 HTTPS Universal Links / Android App Links。

入口通道

通道状态配置位置
Custom schemeIntegratedapp.config.ts 根据 APP_VARIANT 生成 scheme
Universal LinksIntegrated存在 EXPO_PUBLIC_LINKING_DOMAIN 时生成 ios.associatedDomains
Android App LinksIntegrated同一个 domain 会生成带 autoVerify: trueandroid.intentFilters
Web linksIntegrated有 domain 时 createAppLink() 返回 HTTPS URL,否则返回 Expo 生成的 URL

默认 variant:

development -> soar-starter-expo-dev://
preview     -> soar-starter-expo-preview://
production  -> soar-starter-expo://

测试时要使用设备上已安装 build 对应的 scheme。

.env.local 或 EAS environment 中设置公开 domain:

EXPO_PUBLIC_LINKING_DOMAIN=app.example.com

app.config.ts 会生成:

iOS:     applinks:app.example.com
Android: https://app.example.com/* with autoVerify

你仍然需要托管平台关联文件:

平台文件
iOShttps://app.example.com/.well-known/apple-app-site-association
Androidhttps://app.example.com/.well-known/assetlinks.json

如果没有设置 domain,createAppLink() 会回退到 Expo Linking 的 custom scheme URL。

路由解析

lib/deep-links.ts 明确列出允许打开的 app 目标:

/
/component
/showcase
/todos
/me
/profile
/notifications
/refer
/paywall
/redeem-code
/permissions

resolveDeepLinkHref(url) 会解析 URL、标准化 path、保留字符串 query params,并对不在 allow-list 中的目标返回 nullopenDeepLink(url, fallback) 会 push 解析后的路由,或使用 fallback。

通知 Provider 也使用同一个函数处理点击:

openDeepLink(url, "/notifications");

应用内 demo

app/showcase/deep-links.tsx 演示了 Home、Todos、Notifications、Permissions 和 Refer 的生成链接。它调用:

const url = createAppLink(path);
const href = resolveDeepLinkHref(url);
openDeepLink(url);

邀请流程也用这个 helper。lib/referrals.tscreateAppLink("/") 生成邀请链接,app/refer.tsx 通过 native share sheet 分享。

测试链接

custom scheme 可以用 Expo 的 URI helper:

npx uri-scheme open "soar-starter-expo-dev://todos" --ios
npx uri-scheme open "soar-starter-expo-dev://notifications" --android

调试模拟器或 emulator 时,也可以用平台命令:

xcrun simctl openurl booted "soar-starter-expo-dev://refer"
adb shell am start -a android.intent.action.VIEW -d "soar-starter-expo-dev://refer"

测试 HTTPS links 时,先托管关联文件,带着 EXPO_PUBLIC_LINKING_DOMAIN 构建并安装 app,然后运行:

npx uri-scheme open "https://app.example.com/refer" --ios
npx uri-scheme open "https://app.example.com/refer" --android

自定义

  • 新增可打开目标前,先把路由加入 ALLOWED_STATIC_PATHS
  • 保持路由确定、可预期。不要把 secret 放进 query params,因为 URL 可能被系统、analytics 或 crash 工具记录。
  • 如果改了 bundle ID、package name、scheme 或 linking domain,同步更新 app.config.ts
  • 改 scheme、associated domains 或 Android intent filters 后,需要重新构建 native app。

相关页面

On this page