Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49234

Detect navigation direction in canDeactivate

$
0
0

I have implemented a CanDeactivateGuard:

import { Injectable } from '@angular/core';
import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { IDeactivatableComponent } from './ideactivatable-component';

@Injectable()
export class CanDeactivateGuard implements CanDeactivate<IDeactivatableComponent> {
  canDeactivate(
    component: IDeactivatableComponent,
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<boolean> | Promise<boolean> | boolean {
    return component.canDeactivate();
  }
}

Now I want to detect if user is navigating forward or navigating back, because if the user is navigating forward the data is not lost (he will come back later to this route), but if user is navigating back data is lost, so in this case is when we want confirmation.

How can I detect in ActivatedRouteSnapshot or RouterStateSnapshot the navigation direction?

Thank you

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49234

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>