CanActivate

export CanActivate : (hook: (next: ComponentInstruction, prev: ComponentInstruction) =>
                     Promise<boolean>| boolean) => ClassDecorator

exported from angular2/router defined in angular2/src/router/lifecycle_annotations.ts (line 45)

Defines route lifecycle hook CanActivate, which is called by the router to determine if a component can be instantiated as part of a navigation.

The CanActivate hook is called with two ComponentInstructions as parameters, the first representing the current route being navigated to, and the second parameter representing the previous route or null.

@CanActivate((next, prev) => boolean | Promise<boolean>)

If CanActivate returns or resolves to false, the navigation is cancelled. If CanActivate throws or rejects, the navigation is also cancelled. If CanActivate returns or resolves to true, navigation continues, the component is instantiated, and the OnActivate hook of that component is called if implemented.

Example

@Component({selector: 'control-panel-cmp', template: `<div>Settings: ...</div>`}) @CanActivate(checkIfWeHavePermission) class ControlPanelCmp { }