Recently starting out with Ionic, I encountered an issue while developing a basic app that should display a specific page by opening a Local Notification. The problem arises when I create multiple notifications – after clicking on the second notification, the app ends up pushing the new page multiple times, regardless of navigating back to the root page.
I would appreciate any help or insights into what might be causing this behavior.
Below is the code for the root page:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
import { Platform } from 'ionic-angular';
import { Page2Page } from '../page2/page2';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private localNotifications: LocalNotifications, public platform: Platform) {
}
click() {
this.platform.ready().then(() => {
this.localNotifications.schedule({
id: 1,
title: 'Notifica',
text: 'Single LocalNotification',
})
this.localNotifications.on('click').subscribe(() => {
console.log("Notification Subscribed")
this.navCtrl.push(Page2Page);
})
})
}
}
And here is the simple second page:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-page2',
templateUrl: 'page2.html',
})
export class Page2Page {
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad Page2Page');
}
}