jlooper / nativescript-snacks

🍕 Short snippets and videos to help users learn NativeScript
http://www.nativescriptsnacks.com
24 stars 8 forks source link

Navigate to route after push notification is received in main.ts #35

Open krisidmisso opened 7 years ago

krisidmisso commented 7 years ago

Can somebody help me navigate after push notification is received?? I get "cannot read property 'navigate' of undefined"

This code is inside main.ts and there is no class or constructor to initialize variables: ` import { RouterExtensions } from "nativescript-angular/router";

let router: RouterExtensions; setTimeout(() => {

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

firebase.init({ 
    onPushTokenReceivedCallback: function(token) {             
        deviceToken = token;  
        console.log("Firebase push token: " + token);  
    },  
    onMessageReceivedCallback: (message) => {  
       // let router: RouterExtensions; //tried initializing it here but didnt work also

        let link = JSON.stringify(message.website);
        router.navigate(["webViewPage"],{
       clearHistory:true,
       transition: {
        name: "slideTop",
        duration: 800,
        curve: "spring"
        },
        queryParams:{"url": link}, 
        animated: true

      });

    }

.......... `