Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 实现深度链接url导致本地应用无法打开android_Javascript_Android_React Native_React Router_Deep Linking - Fatal编程技术网

Javascript 实现深度链接url导致本地应用无法打开android

Javascript 实现深度链接url导致本地应用无法打开android,javascript,android,react-native,react-router,deep-linking,Javascript,Android,React Native,React Router,Deep Linking,我正在尝试实现与react本机应用程序的深层链接。 问题是,当我的应用程序处于后台时,我尝试打开链接时出错 undefined不是对象(评估'this.props') 如果我的应用程序不在后台(应用程序未运行),它可以正常工作 我的初始路线是应用程序显示大约2.5秒的启动屏幕,然后根据用户是否登录重定向到特定路线,如果用户登录,则将重定向到主路线,否则将重定向到登录路线 这是我的应用程序路线 function mapStateToProps (state) { return { de

我正在尝试实现与react本机应用程序的深层链接。 问题是,当我的应用程序处于后台时,我尝试打开链接时出错

undefined不是对象(评估'this.props')

如果我的应用程序不在后台(应用程序未运行),它可以正常工作

我的初始路线是应用程序显示大约2.5秒的启动屏幕,然后根据用户是否登录重定向到特定路线,如果用户登录,则将重定向到主路线,否则将重定向到登录路线

这是我的应用程序路线

function mapStateToProps (state) {
  return {
    deviceVersion: state.device.version,
    auth: {
      form: {
        isFetching: state.auth.form.isFetching
      }
    },
    global: state.global,
    search: state.search
  }
}


function mapDispatchToProps (dispatch) {
  return {
    actions: bindActionCreators({ ...authActions, ...deviceActions, ...globalActions, ...searchActions }, dispatch)
  }
}

var reactMixin = require('react-mixin')
import TimerMixin from 'react-timer-mixin'
我的componentDidMount函数

componentDidMount () {
            this.setTimeout(
                    () => {
                      this.props.actions.getSessionToken()
                      this.props.actions.setHeight(height)
                      this.props.actions.getIp()
                      this.props.actions.getUniqueId()
                      this.props.actions.getLanguage()
                    },
                    2500
                )
渲染功能

render () {
    return (
      <View style={styles.container}>
        <StatusBar
          backgroundColor="#b33939"
        />
        <View style={{flex:1}}>
        <Header isFetching={this.props.auth.form.isFetching}
          showState={this.props.global.showState}
          currentState={this.props.global.currentState}
          onGetState={this.props.actions.getState}
          onSetState={this.props.actions.setState} />
        </View>

        <View style={{flex:1}}>
          <Text style={styles.summary}>Welcome</Text>
        </View>

      </View>
    )
  }
}

reactMixin(App.prototype, TimerMixin)

export default connect(mapStateToProps, mapDispatchToProps)(App)
handleOpenURL函数如下所示

handleOpenURL(event) {
    console.log('URL', event)

    if(!_.isNull(event.url))
    {
      var url = event.url
      var removeDomain = url.replace("https://www.example.com/", "")
      console.log(removeDomain)
      var lastChar = removeDomain[removeDomain.length -1];
      if(lastChar != '/')
      {
        var data = removeDomain.split("/")
        if(data[0] == 'listing')
        {
          this.props.actions.openListingDetail(data[1], null)
        }
        
      }
    }else{
      this.setTimeout(
            () => {
              this.props.actions.getSessionToken()
              this.props.actions.setHeight(height)
              this.props.actions.getIpAdd()
              this.props.actions.getUniqueId()
              this.props.actions.getLanguage()
            },
            2500
        )
    }
  }
getSessionToken函数用于检查用户是否登录。 我使用的是反应路由器流量

如果应用程序当前未运行,则此操作正常。Url已正确打开列表路径。 如果在没有深度链接url的情况下正常打开,这也可以正常工作。 但是当应用程序在后台时,我遇到了一个错误,它无法执行
this.props.actions.openListingDetail(数据[1],null)
错误消息

undefined不是对象(评估'this.props')


你知道怎么了吗?

看来你是在把一个方法作为静态函数传递给
addEventListener
。你可以试试这个:

componentDidMount () {
  Linking.getInitialURL()
    .then(url => this.handleOpenURL({ url }))
    .catch(console.error);

  Linking.addEventListener('url', () => this.handleOpenURL());
}
希望这有帮助

android:launchMode="singleTask"
componentDidMount () {
  Linking.getInitialURL()
    .then(url => this.handleOpenURL({ url }))
    .catch(console.error);

  Linking.addEventListener('url', () => this.handleOpenURL());
}