【问题标题】:React Navigation deeplink external navigation issueReact Navigation deeplink 外部导航问题
【发布时间】:2019-04-19 14:24:33
【问题描述】:

我有一个实现 react-navigation 的简单应用

const prefix = Platform.OS == 'android' ? 'http://test.in/' : 'http://';
const StackNav = createStackNavigator({
  Home: { screen: MainApp },
  Detail: {
    screen: ContentDetail,
    path: 'content/:contentId',
  },
  NewsDetail: NewsDetail
});

const App = () => <StackNav uriPrefix={prefix} />;

但是当我尝试使用外部链接导航到详细信息屏幕时,它无法导航。

试过

adb shell am start -W -a android.intent.action.VIEW -d "http://www.test.in/content/114" com.test

用于从命令提示符导航

【问题讨论】:

    标签: react-native react-navigation deep-linking


    【解决方案1】:

    您必须添加一个侦听器来处理外部导航的url 事件。看文档:https://facebook.github.io/react-native/docs/linking.html

    componentDidMount() {
        Linking.addEventListener('url', this.handleOpenURL)
      }
    
      componentWillUnmount() {
        Linking.removeEventListener('url', this.handleOpenURL)
      }
    
      handleOpenURL = (event) => {
        somethingWithDeepLink(event.url)
      }
    

    【讨论】:

    • 这应该是react-navigation 作业,因为它创建了顶层对象。没有地方可以添加这段代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 2018-01-10
    • 2018-12-01
    • 2018-04-08
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多