how to redirect to specific route in ionic4 on click of push notification? P.S. I am using https://ionicframework.com/docs/native/fcm.
Hi, @mayurbaldha
Try this:
this.fcm.listenToNotifications().subscribe(data => {
if (data.wasTapped) {
this.router.navigateByUrl('/pageName');
} else {
//Notification was received in the foreground. Maybe the user needs to be notified.
}
});
For more info about navigation Click here
In my case, this works Fine.
Hope it helps.
@addwebsolution : I assume this code is in app.component.ts & Ideally it should work this way only.
But have you tried using a sidemenu pattern of ionic 4?
There are functions which needs to be called if app is loading normal. e.g. login check functions & routings.
If app is loading normally,I can call conditions in app.component.ts and check the same. for login check functions & routings.
but
If my app is launching after click of notification,redirections first loads initial route, then after
this.router.navigateByUrl(’/pageName’); works.
It doesn’t go directly to page.
Any updates in this issue?
Same problem here.
I’m facing same issue. Can you help with it?
I solved this issue with a messy workaround. I dont know if I should be recomending this, lol… But this is what I’ve done.
I have an “Api” provider that I use to call some specific endpoints and make API calls. Then, I altered this class adding a new attribute “navigateTo”, and I set that field on the “notification” event, like this:
push.on(‘notification’).subscribe(
async (msg:any) => {
if(!msg)
return
let addData = msg.additionalData
if(addData.coldstart)
if(addData.navigateTo)
this.Api.navigateTo = addData.navigateTo
Then, after the login event on the app:
if(this.api.navigateTo)
this.router.navigateByUrl(this.api.navigateTo)
else
this.router.navigateByUrl('/home')
Pretty simple, but I just dont know if this is the best way to go. Use this solution at your own risk lol
Thank you so much!! will give a try… thanks alot
No problem, let us know If It worked
Hi, I tried but it’s not working for me… btw thanks for the help
I finally managed to solve my issue by referring to the following