Routing from notification when app is not running

I’m using the OneSignal SDK to handle notifications sent out to users of my app, and depending on what notification is received, the app is supposed to redirect to a specific tab in the app. This works fine if the app is running in the background, but if I close out of the app entirely and then click a notification, it just opens the app and stays on the homepage. Has anyone else run into this and/or have a fix? Thanks!

@vidyaap, I think you may combine with deep-link to do that. Because unless using deep-link, after your close entirely app and you push notifications. This one will default open your homePage without a point to specific your page already write code on your app.

Ciao.

So just to clarify, are you saying the regular Angular routing won’t work if the app isn’t already running?

Nope, if you are not using deeplink to specific your app page. Once your push Notifications external app, and when your click to notifications.

That one is going always open default to your homepage without router to you already point to specific page and if you wanna router to specific page, you must combine with deeplink.

ps: in Android we are using deeplink. And in IOS we are using UniversalLink

I see, thanks, but there are also some posts that say that push notification handlers don’t handle deep links. Also, what I currently do is route to specific tabs within the handlers for the push notifications in app.component.ts. If it doesn’t work there for regular routing, how does it work for deep links?

I am not sure which post have you seen it said doesn’t need deeplink to route specific pages. But for me, push Notifications just help us make a push Notification, it didn’t help us create a deeplink except we must manually one to our app.

There is a capacitor docs tutorial: https://capacitorjs.com/docs/guides/deep-links

and there are example tutorials of Mr. Simmon:
https://devdactic.com/universal-links-ionic/

I understand that you have to implement the routing and the notification separately, but I don’t see why deep links would work any differently than the regular routing. This is what the handlers in app.component.ts look like right now:

constructor(---some params---) {
--- some code ---

  this.initializeApp();

---some more code---
}

initializeApp() {
--- some code ---
  this.oneSignal.handleNotificationReceived().subscribe(data => this.notificationReceived(data));
  this.oneSignal.handleNotificationOpened().subscribe(data => this.notificationOpened(data));
--- some more code --- 
}

async notificationReceived(data: OSNotification) {
  if (data.payload.title === 'Some title') {
    await some_function();
    this.router.navigate(['some/route/path']);
  }
}

async notificationOpened(data: OSNotificationOpenedResult) {
  if (data.notification.payload.title === 'Some title') {
    this.router.navigate(['some/route/path']);
  }
}

If the deep links would go in these event handlers as well, I don’t see why that would work over regular routing.

I have exactly the same problem: have you found a solution?