Linking.getInitialURL() is not being cleared after used for deeplink

前端 未结 2 1794
遥遥无期
遥遥无期 2021-01-21 17:27

I\'ve had this problem for like 2 weeks. I used Wix\'s Navigation for navigating around the app. I followed this tutorial for implementing the deeplink/universal link.

I

2条回答
  •  礼貌的吻别
    2021-01-21 17:49

    There are two ways to handle URLs that open your app.

    1. If the app is already open, the app is foregrounded and a Linking event is fired You can handle these events with Linking.addEventListener(url, callback).

    2. If the app is not already open, it is opened and the url is passed in as the initialURL You can handle these events with Linking.getInitialURL(url) -- it returns a Promise that resolves to the url, if there is one.

    You can read more detail Here is the example

    export default class App extends Component {
      constructor(props) {
        super(props)
        this.state = {
          initialised: false
        }
      }
    
      componentDidMount() {
        AppState.addEventListener('change', this._handleAppStateChange);
        Linking.addEventListener('url', event => {
           console.log('deep link from background', event.url)
        })
      }
    
      _handleAppStateChange = async (nextAppState) => {
        const url = await Linking.getInitialURL();
        if (url !== null && !this.state.initialised) {
          this.setState({ initialised: true })
          console.log('deep link from init app', url)
        }
      }
    
      componentWillUnmount() {
        AppState.removeEventListener('change', this._handleAppStateChange);
        Linking.removeEventListener('url')
      }
    }
    

提交回复
热议问题