#similar to canDeactivate

8 messages · Page 1 of 1 (latest)

hidden zinc
#

is there something similar to a canDeactivate guard in angular that executes certain code before a route change is made? but I don't actually need the functionality of canDeactivate since it will always be true. I just need a way to execute code before similar to it

#

cause my code is like this right now:

  canDeactivate(
    component,
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot,
    nextState: RouterStateSnapshot
  ): Observable<boolean> | Promise<boolean> | boolean {
    if (this.canOpen()) {
        if (this.Change) {
            this.stop();
        }
        else {
          this.save();
        }
    }
    return true;
  }
#

im not actually using the candeactivate functionality i'm just using the ability to execute that code haha

tawdry trout
#

What's your use-case. What do canOpen(), stop() and save() do?

hidden zinc
#

i need something like an attribute in c# or something

tawdry trout
#

A canDeactivate guard looks like the right tool for the job, even if it always returns true.

hidden zinc
#

oh so it's not bad logic to do that