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

使用react-native-router-flux在Android中无法激活Deep Link问题求助

解决React Native Router Flux Android Deep Link无法生效的问题

我之前在使用react-native-router-flux实现Deep Link时,也踩过Android端无法解析Intent的坑,结合你给出的报错信息和参考的PR,给你几个针对性的排查和修复方案:

1. 检查AndroidManifest.xml的Activity配置

这是最容易出问题的环节,必须确保你的主Activity(一般是MainActivity)添加了正确的intent-filter,来匹配你的URL Scheme。

比如你的Deep Link是my-app://my-app,对应的配置应该是这样的:

<activity
  android:name=".MainActivity"
  android:label="@string/app_name"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
  android:launchMode="singleTask"
  android:windowSoftInputMode="adjustResize">
  <!-- 原有启动页配置 -->
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <!-- 新增的Deep Link过滤规则 -->
  <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <!-- 精准匹配scheme和host -->
      <data android:scheme="my-app" android:host="my-app" />
  </intent-filter>
</activity>

注意这里的android:launchMode="singleTask"很关键,它能确保Deep Link打开时不会重复创建Activity实例,同时要保证data标签里的scheme和host完全匹配你的Deep Link地址。

2. 修正adb测试命令

你当前的命令里指定了pkg=com.my-app,可能会限制系统对匹配Activity的查找,试试去掉这个参数,让系统自动匹配:

adb shell am start -a android.intent.action.VIEW -d "my-app://my-app"

或者更明确地指定Activity路径,避免系统混淆:

adb shell am start -n com.my-app/.MainActivity -a android.intent.action.VIEW -d "my-app://my-app"

3. 确认Router Flux的Deep Link处理逻辑

结合你参考的PR,要确保在Router组件里正确配置了Deep Link的回调,比如:

import { Router, Actions } from 'react-native-router-flux';

<Router
  onDeepLink={({ payload }) => {
    // 解析Deep Link的路径,跳转到对应页面
    const urlParts = payload.url.split('://');
    const path = urlParts[1];
    if (Actions[path]) {
      Actions[path]();
    }
  }}
>
  {/* 你的Scene配置,确保key和Deep Link路径完全一致 */}
  <Scene key="my-app" component={MyAppScreen} title="My App" />
</Router>

要保证每个Scene的key和Deep Link里的路径(比如my-app://my-app里的my-app)完全对应,这样Router才能正确识别并跳转。

4. 测试前的必要操作

  • 每次修改AndroidManifest.xml后,必须重新编译Android项目:执行npx react-native run-android,热重载不会生效,因为Manifest的修改需要重新打包。
  • 可以打开Android Studio的Logcat,搜索Intent相关的日志,查看系统无法解析Intent的具体原因,比如是否有多个App匹配了同一个Scheme,或者你的App的权限配置有问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:11:59