Nativescript-plugin-firebase: Navigate to route (view) when push notification is received??

Created on 25 Apr 2017  路  7Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

Hello,
First thank you for the tutorial. It helped me a lot in a project im doing.
Can you please help me with a problem i have redirecting to another view (with parameters) when push is received??

firebase.init({
..............
onMessageReceivedCallback: function(message) {  
let router:Router;
let navigationExtras: NavigationExtras = {
            queryParams: {
                "url": 'http:www.google.com/',
            }
        };
router.navigate(["view-name"], navigationExtras);
}
.........
)}

im getting cannot read property of router "undefined"

Please help!

Most helpful comment

@lumayara are you using angular? if yes, you have to follow exactly the installation guide, and then add this to a component(page) that is opened always (main.ts / app.component.ts / app.module.ts...in my case its home.component.ts):

....
....
let firebase = require("nativescript-plugin-firebase");
....
....
....

export class HomeComponent {
constructor(private router: Router) {

//firebase init function

//handle push notification tap event
 firebase.addOnMessageReceivedCallback(
      (message) => {
       // navigate to a route
       this.router.navigate(["other-page"]);
      }

    );
}
}

All 7 comments

@krisidmisso have you found the solution for this problem?

@krisidmisso did you try to inject router in constructor like this?

constructor( private router: Router ) { }

@hedza06 you can make a separate function and use fat arrow functions:

onMessageReceivedCallback: (message)=>{  
this.navigateTo();
}

.....


function navigateTo() {
let router:Router;
let navigationExtras: NavigationExtras = {
            queryParams: {
                "url": 'http:www.google.com/',
            }
        };
router.navigate(["view-name"], navigationExtras);
}

The problem i have still today is that this works on debug mode, or when build with webpack bundle.....but it doesnt work when i publish the app in app store.

Hope it helps

@krisidmisso Did you set the APN in firebase before publishing?

@hedza06 Im using only Android for the moment. No need for apn :)

Were you able to find a solution? I have the same problem.

@lumayara are you using angular? if yes, you have to follow exactly the installation guide, and then add this to a component(page) that is opened always (main.ts / app.component.ts / app.module.ts...in my case its home.component.ts):

....
....
let firebase = require("nativescript-plugin-firebase");
....
....
....

export class HomeComponent {
constructor(private router: Router) {

//firebase init function

//handle push notification tap event
 firebase.addOnMessageReceivedCallback(
      (message) => {
       // navigate to a route
       this.router.navigate(["other-page"]);
      }

    );
}
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlooper picture jlooper  路  3Comments

vchimev picture vchimev  路  3Comments

NickIliev picture NickIliev  路  3Comments

thunder413 picture thunder413  路  3Comments

b02505048 picture b02505048  路  3Comments