0

My Node.js backend returns the AWS Cognito tokens as JSON which are received in my Angular login Component.

I wish to open my dashboard and pass the received tokens in my login.component.ts function I do: this.router.navigate(['/dashboard', { tokens: data }]); before sending the data I print it to the console and it looks fine

in my dashboard.component.ts I'm not sure why the tokens are not reachable

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

constructor(private route: ActivatedRoute, private router: Router) {}   

ngOnInit() {

this.route.queryParams.subscribe(params => {
            console.log('params = ' + params);
            var data = params['tokens'];
            console.log('data = ' + data);
            for(let key in data){
                console.log('key = ' + key + ' data= ' + data[key]);
            }
        });
}

this is the 'console.log' output params = [object Object] data = undefined

What am I doing wrong?

Kukula Mula
  • 1,788
  • 4
  • 19
  • 38

1 Answers1

0

You are sending params not query params, so your code should be :-

this.route.params.subscribe(params => {
            console.log('params = ' + params);
            var data = params['tokens'];
            console.log('data = ' + data);
            for(let key in data){
                console.log('key = ' + key + ' data= ' + data[key]);
            }
        });
Aakash Garg
  • 10,649
  • 2
  • 7
  • 25