例如,我收到了一个来自本地的特定任务提醒通知。当我点击通知时,我想去该特定任务页面的路径。如何做到这一点,我使用的是ionic cordova本地通知插件,也有电容推送通知。
reminderNotification(id , sec: number , msg , dueDate , dueTime) {
const endTime = sec;
const startTime = this.converToMinutes(dueTime);
const converted = this.parseTime(startTime - endTime);
const date = new Date(dueDate + ' ' + converted );
// tslint:disable-next-line:radix
this.localNotification.clear( parseInt(id) ).then(
() => {
this.localNotification.schedule({
// tslint:disable-next-line:radix
id: parseInt(id),
title: ' Attention ! ' + converted ,
text: 'Your Task "' + msg + '" will expire soon' ,
// data: {msg : 'Lots of data'},
trigger: {
at: date,
// unit: ELocalNotificationTriggerUnit.SECOND
},
silent: false,
lockscreen : true,
foreground : true,
vibrate : true
});
}
);
}
从通知中,我猜想你得到了类似任务id的相关信息。你需要做的就是注入angular router,在收到通知时使用navigate方法。
this.router.navigate(['/TASKS_ROOT_PAGE/TASK_ID']);
更多关于路由器的信息可以在这里找到。https:/angular.ioguiderouter)。