'React Native- Linking.addEventListener works for universal link, but not for a deep link

This is my code:

useEffect(() => {
  Linking.getInitialURL()
    .then(url => {...})
    .catch(err => console.log(err));

  Linking.addEventListener('url', eventHandler);

  return () => {
    Linking.removeEventListener('url', eventHandler);
  };

  }, []);

Everything works perfectly fine for universal links, however, for a deep link, the addEventListener does not work. The app opens up normally but the eventHandler is not being called. However, if the app is closed before opening the deep link, it works fine and executes getInitialURL.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source