I have a problem when I use deep linking android on react native. And when the application is in a foreground state when the application is triggered from deep-linking the application does not refresh on that screen. For example, I want deep linking to the Home Screen but when my foreground is on the profile screen then my application doesn't refresh?
this my code for deeplinking :
async componentDidMount() {
// This for deeplinking
if (Platform.OS === 'android') {
Linking.getInitialURL().then(url => {
this.navigate(url);
});
} else {
Linking.addEventListener('url', this.handleOpenURL);
}
navigate = (url) => {
const { navigate } = this.props.navigation;
const route = url.replace(/.*?:\/\//g, '');
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (id === 'yes') {
alert(id)
}
}
We can use property from react native firebase, which can detect app in foreground, background nor in app. documentation if you used notification for your app. And if you not you can use didFocus() from react navigation.