React native getInitialURL not nullify after use

939 Views Asked by At

After using Linking.getInitialURL() the URL stay there.

I am using react-native-router-flux to navigate.

when users log out I run

   import { NativeModules } from 'react-native';
    NativeModules.DevSettings.reload()

What happens is the react-navigation do Linking.getInitialURL() and if there any result so it navigates automatically to the page.

how to reset Linking.getInitialURL() after use ? happens only on android

1

There are 1 best solutions below

0
satya164 On

React Navigation 5 provides an option to specify a custom getInitialURL method which you can use:

<NavigationContainer
  linking={{
    // ... linking config
    getInitialURL() {
      return YourCustomModule.getInitialURL();
    },
  }}
>
  {/* content */}
</NavigationContainer>

https://reactnavigation.org/docs/navigation-container/#linkinggetinitialurl

For the implementation, since you're reloading the whole JS, the code cannot be in JS as the state is lost on reload. You'll need to write a custom native module where you can clear the initial URL when reloading.