FCM Push notification redirect/navigate not working when App Killed

Hi All,

I am using Push notification with Firebase using cordova-plugin-fcm-with-dependecy-updated taking examples from documentation https://ionicframework.com/docs/native/fcm

I have also created Rest API using Firebase. Below is the code for rest API

$msg = array
		(
			'body' 	=> "Body Message",
			'title'	=> "Title",
			'icon'	=> 'myicon',/*Default Icon*/
			'sound' => 'mySound',/*Default sound*/
		       'click_action' => 'FCM_PLUGIN_ACTIVITY'		
		);
		
		$data1=array
		(
			'dataorderid' => 'Order Number'
		 );
		
		
		$fields = array
		(
			'registration_ids' => 'FCM Token',
			'notification'	=> $msg,
			'data' => $data1
		);
		
		$headers = array
		(
			'Authorization: key=' . API_ACCESS_KEY,
			'Content-Type: application/json'
		);
#Send Reponse To FireBase Server	
		$ch = curl_init();
		curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
		curl_setopt( $ch,CURLOPT_POST, true );
		curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
		curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
		curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
		print_r(curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ));
		$result = curl_exec($ch );
		curl_close( $ch );

Above code is working fine and sending notification to APP. However, when app is killed and i tap on notification message it does NOT redirect to the intended screen.
It is working fine and redirecting to intended screen if APP is in background or foreground.

Below is the code in my app.component.ts where it’s subscribing.

initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
	  this.fcm.getToken().then(token => {
		//sending to fcm
	  });
	  
	this.fcm.onNotification().subscribe(data => {

    if (data.wasTapped) {

      console.log('Received in background');
	 this.router.navigate(['/location',{locationdata:data.dataorderid}],{ replaceUrl: true });

    } else {

         console.log('Received in foreground');
	 this.router.navigate(['/location',{locationdata:data.dataorderid}],{ replaceUrl: true });
    }

  });  
	  
	  
    });
  }

Only problem, i am facing is that when App is killed and receive notification, i tap on that notification, it’s just opening the App and showing home screen but it has to navigate to some other screen. When app is closed in background or in foreground, its working perfectly.
What can be the problem here? Please help.

Below is my Ionic’s environment details.

Ionic:

   ionic (Ionic CLI)             : 4.11.0 (C:\Users\USERNAME\AppData\Roaming\nvm\v10.16.3\node_modules\ionic)
   Ionic Framework               : @ionic/angular 5.3.2
   @angular-devkit/build-angular : 0.1000.8
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms     : android 8.1.0, ios 5.1.1
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 6 other plugins)

System:

   NodeJS : v10.16.3 (C:\Program Files\nodejs\node.exe)
   npm    : 6.9.0
   OS     : Windows 7

Please guide or help me to sort out this problem App navigate to intended screen even it’s killed.

Thanks,
Zack

May be you should research on how to send a payload in the message to a closed app and then subsequently how to handle or process the payload which could even be url in your app.

Check out the Firebase docs for JS:
Receive messages in a JavaScript client
About FCM messages

Because data messages don’t support fcm_options.link , you are recommended to add a notification payload to all data messages. Alternatively, you can handle notifications using the service worker.