Answers for "CanDeactivate does not work if we click on cancel in the first time"

0

CanDeactivate does not work if we click on cancel in the first time

export class CanDeactivateGuard implements CanDeactivate<any> {
    constructor(
        private readonly location: Location,
        private readonly router: Router
    ) {}

    canDeactivate(component: any, currentRoute: ActivatedRouteSnapshot): boolean {
        if (myCondition) {
            const currentUrlTree = this.router.createUrlTree([], currentRoute);
            const currentUrl = currentUrlTree.toString();
            this.location.go(currentUrl);
            return false;
        } else {
            return true;
        }
    }
}
Posted by: Guest on April-29-2021

Code answers related to "CanDeactivate does not work if we click on cancel in the first time"

Browse Popular Code Answers by Language