已配置Deep Linking仍失效,如何在Expo版React Native项目配置Universal Linking?
Alright, let's get that universal linking sorted out for your Expo app! You already have deep links working when sharing from the app and clicking links in messages, but the problem hits when the app's already installed—totally frustrating, I've been there. Here's a step-by-step guide to fix this:
First, you need to add the universalLinks field to your app.json or app.config.js file under the expo section. This tells Expo which domains should trigger your app.
Example configuration:
"expo": { // ... your existing configs "universalLinks": { "domains": ["your-custom-domain.com"], // Optional: Restrict links to specific paths if needed "paths": ["/*", "/content/*"] } }
iOS uses the AASA file to verify that your domain is authorized to open your app. You'll need to host this file at the root of your domain (no .json extension allowed) at https://your-custom-domain.com/apple-app-site-association.
The file content should look like this—replace TEAM_ID with your Apple Developer Team ID and BUNDLE_ID with your app's bundle ID:
{ "applinks": { "apps": [], "details": [ { "appID": "TEAM_ID.BUNDLE_ID", "paths": ["/*"] } ] } }
Important: Make sure the file is served with the Content-Type: application/json header. You can test this using curl -I https://your-custom-domain.com/apple-app-site-association in your terminal.
For Android, you'll host a assetlinks.json file at https://your-custom-domain.com/.well-known/assetlinks.json. This links your domain to your app's package name and signing certificate.
Here's the template—replace com.your.app with your app's package name and YOUR_SHA256_FINGERPRINT with the SHA-256 fingerprint of your signing certificate (you can get this from Expo's build dashboard or your local keystore):
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.your.app", "sha256_cert_fingerprints": ["YOUR_SHA256_FINGERPRINT"] } } ]
Like the AASA file, ensure this is served with Content-Type: application/json.
- iOS: Universal links don't work reliably on simulators, so test on a real device. Run
expo prebuildto generate native files, build the app, install it, then open your domain URL in Safari. If it redirects to your app instead of loading the web page, you're good to go. - Android: Test on a real device too. Build the app, install it, then click your domain link from a browser or another app. You can also use this adb command to test directly:
adb shell am start -W -a android.intent.action.VIEW -d "https://your-custom-domain.com"
Note: Expo Go doesn't support universal links—you'll need to use a custom development client or production build to test fully.
- Links still opening the web: Double-check that your AASA/DAL files are correctly formatted, hosted at the exact paths, and have the right team ID/bundle ID/package name.
- iOS cache issues: iOS caches the AASA file heavily. Uninstall the app, restart your device, then reinstall to clear the cache.
- Expo changes not taking effect: After updating
app.json, runexpo publishor rebuild your app—simple changes won't apply until you do this.
内容的提问来源于stack exchange,提问作者Efe Imoloame




