question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating to a route after tapping a notification

See original GitHub issue

Is there a way I can make the app launch a specific route other than the home after I tap a notification? Or navigate to a route after I tap the notifcation?

im doing this to register the callback for tapping a notification:

ngOnInit() {
        LocalNotifications.addOnMessageReceivedCallback((notification) => {
          
            this.routerExtension.navigate(["/details", notification.id]);
        })
    }

But i get this error: Navigation triggered outside Angular zone, did you forget to call ‘ngZone.run()’?

I tried wrapping it around ngZone.run() but I still get the same error:

ngOnInit() {
        LocalNotifications.addOnMessageReceivedCallback((notification) => {

             this._zone.run(() => {
                 this.routerExtension.navigate(["/details", notification.id]);
             })
        })
    }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
EddyVerbruggencommented, May 20, 2019

If this is an issue on Android only, try adding this launchMode to <activity android:launchMode="singleTask" in AndroidManifest.xml.

0reactions
danielnitucommented, Aug 1, 2019

Had the same issue and was able to make it work with NgZone.

setLocalNotificationsCallback() {
    LocalNotifications.addOnMessageReceivedCallback(notification => this.ngZone.run(() => {
        console.log('NOTIFICATION TAPPED', notification)
        this.router.navigate(['main'])
    })).then(() => {
        console.log('NOTIFICATIONS CALLBACK ADDED')
    }).catch(err => {
        console.log('ERROR ADDING NOTIFICATIONS CALLBACK', err)
    })
}

Add the function to app.component.ts and invoke it in ngOnInit.

I’m not 100% sure if this is something that can be corrected. Since the library is made to work with any NS platform, it will run outside Angular’s zone, unless it is specifically redesigned for Angular.

Angular 7.2.15 Core 5.4.3 local-notifications 3.2.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter: FCM — How to Navigate to a Particular Screen After ...
In this post, I'll go over how to receive FCM Push Notifications and then push a particular page when the user taps on...
Read more >
Navigate to screen after opening a notification? - Stack Overflow
Best way to handle navigation on notification opening is to handle them in a splash screen. this will give ...
Read more >
Start an Activity from a Notification - Android Developers
When you start an activity from a notification, you must preserve the user's expected navigation experience. Tapping Back should take the ...
Read more >
Open app in specific view when push notification is tapped
(Notice that after tapping the push notification, the app moves to the ... and then the navigation controller, and finally the specific view ......
Read more >
Turn Google Maps notifications on or off - Android
To check things that interest you, like train schedules or traffic on routes you travel often, turn on notifications in the Google Maps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found