反应导航深层链接外部导航问题

时间:2018-11-16 11:40:10

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

我有一个简单的应用程序,可以实现反应导航

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

用于从命令提示符导航

1 个答案:

答案 0 :(得分:0)

您必须添加一个用于处理外部导航的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)
  }
相关问题