Passing data via AuthGuard

I have a couple pages in my app which require authentication, and several that don’t. Instead of making everyone login, I’ve set up an AuthGuard that restricts access to those to pages. This is working as expected.

I now want to pass data to my login page so that, after login, the user is redirected to the page they are trying to access. I’m unsure on how to do this.

From what I could find, I pass the value in via data

    path: 'map', loadChildren: './map/map.module#MapPageModule', canActivate: [AuthGuard], 
    data: { page: 'map' }

But how do I read this on my login page so I can send them to the proper page, something like this?

if( data == 'map') {

canActivate(ars: ActivatedRouteSnapshot, rss: RouterStateSnapshot): boolean {
  // restrict user access-------------------------------------------------------------
  let canProceed = this.loginService.getUserAccessLevelValue() >=;
  if (canProceed == false) {
    if ( == 4) {
      this.showAlert('Access Denied - canActivate', 'You must be an Administrator to view this page');
    } else {
      this.showAlert('Please Login - canActivate', 'You must be logged in to view this page');

    // go to the login page, passing the next page to go to
    this.router.navigate(['/login', { 'nextPage': rss.url }]);
    return false;

Figured it out.

data was not being passed to the, however it was being passed to auth.guard.ts, so all I had to do was capture it there and send it as a queryParam to


import { Router, CanActivate, ActivatedRouteSnapshot } from '@angular/router';

canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
    this.router.navigate(['/login'], { queryParams: });

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

page: any;

constructor(public route: ActivatedRoute) {
    this.route.queryParams.subscribe((res) => { =;

login(formData: any) {
    if ( === 'map') {