关于在你的 Expo 应用中实现链接和深层链接的可用资源的概述。
¥Linking
链接允许你的应用与传入和传出 URL 进行交互。在此过程中,用户不仅会被引导打开你的应用,而且还会被带到应用内的特定屏幕(路由)。
¥Linking allows your app to interact with incoming and outgoing URLs. In this process, the user not only gets directed to open your app, but they are taken to a specific screen (route) within the app.
¥Linking strategies
你在 Expo 应用中处理不同的链接策略:
¥There are different linking strategies you handle in your Expo app:
使用你的 Web 域链接链接到你的应用(通用链接 使用 https
或 http
方案)
¥Linking to your app using your web domain links (universal linking using the https
or http
scheme)
使用自定义方案(深层链接)从其他应用或网站链接到你的应用
¥Linking to your app from other apps or websites using a custom scheme (deep links)
从你的应用链接到其他应用(传出链接)
¥Linking to other apps from your app (outgoing links)
提示:Expo Go 中对传入链接的支持有限。我们建议使用 开发构建 来测试你的应用的链接策略。
¥Universal linking
如果安装了应用,Android 和 iOS 都实现了自己的系统来将 Web URL 路由到应用。在 Android 上,此系统称为 App Links,在 iOS 上称为 Universal Links。这两个系统的先决条件是你有一个 Web 域,你可以在其中托管一个文件来验证你对域的控制。
¥Both Android and iOS implement their own systems for routing web URL's to an app if the app is installed. On Android, this system is called App Links, and on iOS it is called Universal Links. The pre-requisite for both systems is that you have a web domain where you can host a file which verifies you control the domain.
¥Android App Links
Android App Links 与 支持的 SDK 版本 不同,因为它们使用常规 HTTP 和 HTTPS 方案并且是 Android 设备独有的。
¥Android App Links are different from standard deep links as they use regular HTTP and HTTPS schemes and are exclusive to Android devices.
此链接类型允许你的应用在用户单击链接时始终打开,而不是从设备上显示的对话框中选择浏览器或其他处理程序。如果用户未安装你的应用,则链接会将他们带到你应用的关联网站。
¥This link type allows your app to always open when a user clicks the link instead of choosing between the browser or another handler from a dialog displayed on the device. If the user doesn't have your app installed, the link takes them to your app's associated website.
Learn how to configure intentFilters
and set up two-way association from a standard web URL.
¥iOS Universal Links
iOS 通用链接与 支持的 SDK 版本 不同,因为它们使用常规 HTTP 和 HTTPS 方案,并且是 iOS 设备独有的。
¥iOS Universal Links are different from standard deep links as they use regular HTTP and HTTPS schemes and are exclusive to iOS devices.
此链接类型允许你的应用在用户单击指向你的网络域的 HTTP(S) 链接时打开。如果用户未安装你的应用,则链接会将他们带到你应用的关联网站。你可以通过显示横幅让用户使用 苹果智能横幅 打开你的应用来进一步配置网站。
¥This link type allows your app to open when a user clicks an HTTP(S) link pointing to your web domain. If the user doesn't have your app installed, the link takes them to your app's associated website. You can further configure the website by displaying a banner for the user to open your app using Apple Smart Banner.
Learn how to configure associatedDomains
and set up two-way association.
¥Linking to your app from other apps or websites
深层链接 是指向应用或网站内特定基于 URL 的内容的链接。
¥Deep Links are links to a specific URL-based content inside an app or a website.
例如,通过点击产品广告,你的应用将在用户的设备上打开,他们可以查看该产品的详细信息。用户单击的此产品链接可能看起来像(或者由设置 window.location.href
的 JavaScript 调用):
¥For example, by clicking a product advertisement, your app will open on the user's device and they can view that product's details. This product's link that the user clicked may look like (or alternatively be invoked by JavaScript with setting window.location.href
):
<a href="myapp://web-app.com/product">View Product</a>
此链接由三部分构成:
¥This link is constructed by three parts:
方案:标识应打开 URL 的应用的 URL 方案(例如:myapp://
)。对于非标准深层链接,它也可以是 https
或 http
。我们建议使用 通用链接 进行基于 http(s) 的深层链接。
¥Scheme: The URL scheme that identifies the app that should open the URL (example: myapp://
). It can also be https
or http
for non-standard deep links. We recommend universal linking for http(s)-based deep links.
主机:应打开 URL 的应用的域名(例如:web-app.com
)。
¥Host: The domain name of the app that should open the URL (example: web-app.com
).
路径:应打开的屏幕的路径(例如:/product
)。如果未指定路径,用户将进入应用的主屏幕。
¥Path: The path to the screen that should be opened (example: /product
). If the path isn't specified, the user is taken to the home screen of the app.
了解如何配置自定义 URL 方案以创建应用的深层链接。
¥Use Expo Router to handle deep linking
要实现上述任何链接策略,我们建议使用 Expo 路由,因为深度链接会自动为你应用的所有屏幕启用。
¥To implement any of the above Linking strategies, we recommend using Expo Router since deep linking is automatically enabled for all of your app's screens.
好处:
¥Benefits:
Expo Router 中的 Link
组件可用于 处理到其他应用的 URL 方案
¥Link
component from Expo Router can be used to handle URL schemes to other apps
Android App Links 和 iOS Universal Links 需要在 JavaScript 中为应用中的链接配置运行时路由。使用 Expo Router,你不必单独配置运行时路由,因为所有路由的深层链接都会自动启用。
¥Android App Links and iOS Universal Links require configuring runtime routing in JavaScript for the link in your app. Using Expo Router, you don't have to configure runtime routing separately since deep links for all routes are automatically enabled.
对于第三方深层链接,你可以覆盖默认链接行为以处理传入链接并发送导航事件。参见 自定义链接。
¥For third-party deep links, you can override the default linking behavior to handle incoming links and send navigation events. See Customizing links.
¥Linking to other apps from your app
使用基于目标应用的 URL 方案的 URL 可以从你的应用链接到其他应用。此 URL 方案允许你引用该原生应用中的资源。
¥Linking to other apps from your app is achieved using a URL based on the target app's URL scheme. This URL scheme allows you to reference resources within that native app.
你的应用可以使用 通用 URL 方案 作为默认应用,包括 https
和 http
(通常由 Chrome、Safari 等 Web 浏览器使用),并使用 JavaScript 调用启动相应原生应用的 URL。
¥Your app can use a common URL scheme for default apps, including https
and http
(commonly used by web browsers like Chrome, Safari, and so on), and use JavaScript to invoke the URL that launches the corresponding native app.
了解如何处理常见和自定义 URL 方案以从你的应用链接其他应用。