You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

点击浏览器链接时如何打开React Native Expo应用的指定屏幕?

问题修复方案
  • 补全链接前缀配置
    你当前的prefixes仅包含Expo生成的本地测试前缀,未添加目标业务域名,需要修改为:
import * as Linking from "expo-linking";

const linking = {
  prefixes: [
    Linking.makeUrl("/"), // 保留本地开发测试用的exp://前缀
    "https://staging.wapal.com" // 新增你的业务域名前缀
  ],
  // 其他配置
};
  • 修正屏幕路径映射规则
    你要匹配的链接路径是/reset/password,当前配置的路径值Resetpassword和实际路径完全不匹配,修改screens配置为:
const linking = {
  prefixes: [
    Linking.makeUrl("/"),
    "https://staging.wapal.com"
  ],
  screens: {
    ResetPassword: "reset/password"
  },
};

配置完成后,点击https://staging.wapal.com/reset/password?token=xxx就会自动打开ResetPassword页面,链接携带的token参数会自动注入到页面的路由参数中,你可以在页面内通过以下方式获取:

import { useRoute } from '@react-navigation/native';

// 页面内逻辑
const route = useRoute();
const token = route.params?.token;
  • 配置域名关联(必做,否则系统不会把链接跳转交给你的应用处理)
    需要在项目的app.json/app.config.js中添加对应配置,完成苹果Universal Links、安卓App Links的域名关联声明:
{
  "expo": {
    // 其他原有配置
    "ios": {
      "associatedDomains": ["applinks:staging.wapal.com"]
    },
    "android": {
      "intentFilters": [
        {
          "action": "VIEW",
          "autoVerify": true,
          "data": [
            {
              "scheme": "https",
              "host": "staging.wapal.com",
              "pathPrefix": "/reset/password"
            }
          ],
          "category": ["BROWSABLE", "DEFAULT"]
        }
      ]
    }
  }
}

修改完成后重新打包应用生效,开发阶段可以用npx uri-scheme open https://staging.wapal.com/reset/password?token=test123 --ios/--android命令本地测试跳转逻辑。

内容的提问来源于stack exchange,提问作者Mir Stephen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 01:57:03