Ionic does not navigate to specified URL after push notification

I have an ionic chat app that receives push notifications from firebase cloud functions…you click the icon and the app open. The problem is it’s not navigating to the specified page when the notification is received in the background, only in the foreground

initializeApp() {
    if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig);
    }

    this.platform.ready().then(() => {
        const unsubscribe = firebase.auth().onAuthStateChanged( user => {
          if (!user) {
            this.router.navigateByUrl('login');
            unsubscribe();
          } else {
            this.router.navigateByUrl('tabs');
            unsubscribe();
          }
        });
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      this.getDeviceToken();
    });
  }

  getDeviceToken() {
    this.fcm.onNotification().subscribe(data => {
      if (data.wasTapped) {
        this.router.navigateByUrl('tabs/connections');

        console.log("Received in background", data.wasTapped);
      } else {
        console.log("Received in foreground", data.wasTapped);
        this.router.navigateByUrl('tabs/connections');
      }
    });

    this.fcm.onTokenRefresh().subscribe(token => {
      // Register your new token in your back-end if you want
      this.fcmService.saveTokenToFirestore(token, this.loggedInUser.uid);
    });
  }
 

if the app is open and it receives a push notification in the foreground it will navigate to the specified page, but not when it’s closed.

I doubt these errors that appear when I open the app has anything to do with it…they were there before push notifications and they haven’t encumbered any functionality…just thought it was worth mentioning:

Failed to load resource: the server responded with a status of 404 ()
polyfills.js:3040 Unhandled Promise rejection: Error Status 404: App not found ; Zone: <root> ; Task: Promise.then ; Value: Error: Error Status 404: App not found
    at IonicDeployImpl.<anonymous> (/plugins/cordova-plugin-ionic/dist/common.js:291)
    at step (/plugins/cordova-plugin-ionic/dist/common.js:37)
    at Object.next (/plugins/cordova-plugin-ionic/dist/common.js:18)
    at fulfilled (/plugins/cordova-plugin-ionic/dist/common.js:9)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:2749)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:2508)
    at polyfills.js:3247
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2781)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:2553)
    at drainMicroTaskQueue (polyfills.js:2959) Error: Error Status 404: App not found
    at IonicDeployImpl.<anonymous> (http://localhost/plugins/cordova-plugin-ionic/dist/common.js:291:35)
    at step (http://localhost/plugins/cordova-plugin-ionic/dist/common.js:37:23)
    at Object.next (http://localhost/plugins/cordova-plugin-ionic/dist/common.js:18:53)
    at fulfilled (http://localhost/plugins/cordova-plugin-ionic/dist/common.js:9:58)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost/polyfills.js:2749:26)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost/polyfills.js:2508:43)
    at http://localhost/polyfills.js:3247:34
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost/polyfills.js:2781:31)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost/polyfills.js:2553:47)
    at drainMicroTaskQueue (http://localhost/polyfills.js:2959:35)

Otherwise, I’m not getting any errors in the console. ALSO, it’s not console logging “console.log(“Received in background”, data.wasTapped);”

It will console.log “console.log(“Received in foreground”, data.wasTapped);”

Again, this is Ionic 4 with Firebase…any help would be greatly appreciated.

1 Like

Hi, Have you solved the issue? Please help me… I’m facing the same issue