2015-07-28 01:12:30 -04:00
.l-main-section
h2 CanActivate <span class="type">variable</span>
p.location-badge.
exported from <a href='../router'>angular2/router</a>
2015-08-11 20:09:57 -04:00
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.34/modules/angular2/src/router/lifecycle_annotations.ts#L41-L43">angular2/src/router/lifecycle_annotations.ts (line 41)</a>
2015-07-28 01:12:30 -04:00
:markdown
2015-08-11 20:09:57 -04:00
Defines route lifecycle method [canActivate], which is called by the router to determine
if a component can be instantiated as part of a navigation.
Note that unlike other lifecycle hooks, this one uses an annotation rather than an interface.
This is because [canActivate] is called before the component is instantiated.
If `canActivate` returns or resolves to `false`, the navigation is cancelled.
If `canActivate` throws or rejects, the navigation is also cancelled.
## Example
```
@Directive({
selector: 'control-panel-cmp'
})
@CanActivate(() => checkIfUserIsLoggedIn())
class ControlPanelCmp {
// ...
}
```
2015-07-28 01:12:30 -04:00