Ionic 4, OneSignal push notification click route to a page not working

My code is working when my app running. but when app was closed it’s not working…

this is my app.component.ts file

I am using php api to create notification using onesignel. I attached some data to notification and I use it for navigate. actually that data is my navigation route…

import { Component } from '@angular/core';
 import { Platform, AlertController } from '@ionic/angular';
 import { StatusBar } from '@ionic- native/status-bar/ngx';
 import { OneSignal } from '@ionic-native/onesignal/ngx';
 import { Router } from '@angular/router';

@Component({
   selector: 'app-root',
 templateUrl: 'app.component.html'
    })
export class AppComponent {
 constructor(
private platform: Platform,
private statusBar: StatusBar,
private oneSignal: OneSignal,
private router: Router,
public alertController: AlertController,
public home: HomePage
) {
this.initializeApp();
}

initializeApp() {
this.platform.ready().then(() => {
  this.statusBar.styleDefault();

this.oneSignal.startInit('xxxxxxxxxxxx', 'xxxxxxx');

this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

  this.oneSignal.handleNotificationReceived().subscribe(() => {
   // do something when notification is received

  });

  this.oneSignal.handleNotificationOpened().subscribe((data: any) => {
    // do something when a notification is opened

    if (data.notification.payload.additionalData.url && data.notification.payload.additionalData.id) {


      let rout = data.notification.payload.additionalData;

      let path = rout.url;

      let id = rout.id;

       let route = '/tabs/' + path + '/' + id;

       this.router.navigateByUrl(route);

    } else {

        // this.home.testnoti(JSON.stringify(data), JSON.stringify(data.notification.payload.additionalData));

      }


  });

  this.oneSignal.endInit();

 });
}
}
3 Likes