Deeplinked screen automatically returning to previous screen – ReactNative Android Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Deeplinked screen automatically returning to previous screen – ReactNative Android without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m creating a notification reminder application in react native, I tried opening a specific screen in the application when user taps on the notification, I’m using react-navigation and tried deep linking with the screen paths. so my problem is, the deep-linked screen is opening fine when the app is foreground already, but if I open the notification when the app is closed(even not in recent), it goes to the deep-linked screen and immediately going back to the previous screen.

I’m doing some async operations in the useEffect. not sure if this is the issue, help can be greatly appreciated.

useEffect(() => {
   const paramObject = navigation.getParam('someObject', {});
   if (Object.keys(paramObject).length === 0) {
      const resourceID = navigation.getParam('resource_id', '');
      const target = navigation.getParam('target', '');
      axios.get().then(() => { 
      // some state setting 
      }).catch(); #Some api call
   }
}, []);

Note: Problem occurs when the deeplink page opens when the app is closed, I’m also getting some warnings with the problem like Can’t Perform react state update on a unmounted component …

Answer

I think your problem is the app navigate to initial route.

Forced the deep linking to wait 1000ms before doing anything, so that sure that the app finished loading properly before anything.

Another approach would be to modify your dynamic initialRoute in order to recognize that the app has been opened by deep linking and to not do anything in that scenario.

We are here to answer your question about Deeplinked screen automatically returning to previous screen – ReactNative Android - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji