Для людей, имеющих один и тот же вопрос, я нашел решение, используя события.Возможно, это не лучшее решение, но оно работает.
Сначала необходимо добавить следующие компоненты на страницу .ts
import { Events } from 'ionic-angular';
import { App } from 'ionic-angular';
Следующая функция срабатывает, когда пользователь нажимает push-уведомление, используяOneSignal.
this.oneSignal.handleNotificationOpened().subscribe((data) => {
// do something when a notification is opened
// the following two lines pass data I send with the push notification so the app knows what to open
let pushaction = data.notification.payload.additionalData.action;
let pushactionvalue = data.notification.payload.additionalData.actionvalue;
// this fires up the tab-switching
this.runNotificationAction(pushaction, pushactionvalue);
});
Следующая функция направляет пользователя на правую вкладку
runNotificationAction(pushaction, pushactionvalue){
// this is the data passed the the other page
let data = {"action": pushaction, "value:": pushactionvalue};
// this opens the right tab. Make sure to change select '0' to the required tab (0 is the first one).
this.app.getRootNav().getActiveChildNav().select(0);
// fires the function that passed the data. Using second parameter to filter event listeners per page.
this.sendData(data, 'homepage');
}
И функцию, которая передает данные на другие страницы:
sendData(data, command){
//We set a timeout because I had problems with sending it imediatly. Like this it works fine for me.
setTimeout(() => {
let pushcommand = "pushData:" + command ;
this.events.publish(pushcommand, data);
}, 500);
}
И наконец, мы должны добавить прослушиватель событий на другие вкладки / страницы, на которые вы будете перенаправлять.
// making an event listerner command for each page like pushData:homepage makes sure the action is only fired from the specific page
this.events.subscribe('pushData:homepage', (data) => {
console.log('Yes, data passed!');
console.log(data);
// Then you can fire your function and use the data
});
Если у кого-то есть какие-либо вопросы, не стесняйтесь задавать!