42 lines
1.0 KiB
Plaintext
42 lines
1.0 KiB
Plaintext
|
|
p.location-badge.
|
|
exported from <a href='../router'>angular2/router</a>
|
|
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/router/interfaces.ts#L115-L139">angular2/src/router/interfaces.ts (line 115)</a>
|
|
|
|
:markdown
|
|
Defines route lifecycle method [canDeactivate], which is called by the router to determine
|
|
if a component can be removed as part of a navigation.
|
|
|
|
If `canDeactivate` returns or resolves to `false`, the navigation is cancelled.
|
|
|
|
If `canDeactivate` throws or rejects, the navigation is also cancelled.
|
|
|
|
## Example
|
|
```
|
|
@Directive({
|
|
selector: 'my-cmp'
|
|
})
|
|
class MyCmp implements CanDeactivate {
|
|
canDeactivate(next, prev) {
|
|
return askUserIfTheyAreSureTheyWantToQuit();
|
|
}
|
|
}
|
|
```
|
|
|
|
|
|
.l-main-section
|
|
h2 Members
|
|
.l-sub-section
|
|
h3#canDeactivate canDeactivate
|
|
|
|
|
|
pre.prettyprint
|
|
code.
|
|
canDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction)
|
|
|
|
:markdown
|
|
|
|
|
|
|
|
|