I want to open a particular page of my app on notification click.(Ionic2)

I am developing push notification application in Ionic2.Notifications are coming. I want to open a particular page of my app on notification click(PushPage).I want to direct it to the page according to the incoming datas such as Instagram(Facebook,Twitter…).How can I listen to the notification click event.

app.component.ts

import { Component,ViewChild } from '@angular/core';
import { Platform,NavController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { FCM } from '@ionic-native/fcm';


import { HomePage } from '../pages/home/home';
import {PushPage} from '../pages/push/push';
declare var FCMPlugin;
@Component({
  templateUrl: 'app.html',
 providers :[FCM]

})
export class MyApp {
rootPage:any = HomePage;
@ViewChild(NavController) nav;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private fcm: FCM
 ) {
   platform.ready().then(() => {
  
   statusBar.styleDefault();
   splashScreen.hide();



 fcm.subscribeToTopic('marketing');
 fcm.getToken().then(token=>{

})

 fcm.onNotification().subscribe(data=>{
 if(data.wasTapped){
   console.log("Received in background");

   this.nav.push(PushPage); 
  } else {
    console.log("Received in foreground");
   this.nav.push(PushPage);
  };
})

 fcm.onTokenRefresh().subscribe(token=>{

})
fcm.unsubscribeFromTopic('marketing');

  });

 }

}
1 Like