Angular 单击“本地通知”时转到特定路径

Angular 单击“本地通知”时转到特定路径,angular,ionic-framework,push-notification,localnotification,capacitor,Angular,Ionic Framework,Push Notification,Localnotification,Capacitor,例如,我收到了来自特定任务提醒的本地通知。当我点击通知时,我想进入带有路径的特定任务页面。如何做到这一点,我使用离子科尔多瓦本地通知插件,也电容器推送通知 reminderNotification(id , sec: number , msg , dueDate , dueTime) { const endTime = sec; const startTime = this.converToMinutes(dueTime); const conve

例如,我收到了来自特定任务提醒的本地通知。当我点击通知时,我想进入带有路径的特定任务页面。如何做到这一点,我使用离子科尔多瓦本地通知插件,也电容器推送通知

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']);

此处提供了有关路由器的更多信息:

但是如何从通知中检索taskId?这实际上取决于通知的实现方式,例如特定的库。通知中肯定有内容,其中应该包括任务id。如果您对此通知没有控制权,并且其中没有任务id,则在前端无法执行太多操作。。。