Capacitor Push Notification: navigate to route when the app is not in background

Hello!

Ionic 6 + capacitor 3 app.

The push notifications are working well in my app, tough I have one “problem”:
in my code I have this section:

    PushNotifications.addListener(
      'pushNotificationActionPerformed',
      async (notification: ActionPerformed) => {
        const data = notification.notification.data;
        if (data.internalRoute) {
          this.routingService.navigateByUrl('/' + data.internalRoute);
        }
      }
    );

If the app is running, everything works as expected otherwise, the first time I get a push notification it just open the App and only after this (doesn’t matter if the app is now running in background or foreground) if I send a new push notification, it navigates to the chosen route. (basically, it goes to the route only if the app is “loaded”)

I think it doesn’t work because that fragment of code is being executed while the app is not completely “running”, so it does nothing.

There is any way to translate my code in something like

**Wait for the app to be completely "awake" and only then execute this:**
 
this.routingService.navigateByUrl('/' + data.internalRoute);
 

thank you!

1 Like

I am also searching for the solution. Any updates on this issue?

nothing.
The only difference I see now is between ios and android: ios keeps the app running in background and if i open it after a long period, it starts from the last point, android starts from the first page.