
This is part of ongoing work to make core platform-independent. BREAKING CHANGE All private exports from 'angular2/src/core/facade/{lang,collection,exception_handler}' should be replaced with 'angular2/src/facade/{lang,collection,exception_handler}'.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/**
|
|
* This indirection is needed to free up Component, etc symbols in the public API
|
|
* to be used by the decorator versions of these annotations.
|
|
*/
|
|
|
|
import {makeDecorator} from 'angular2/src/core/util/decorators';
|
|
import {CanActivate as CanActivateAnnotation} from './lifecycle_annotations_impl';
|
|
import {Promise} from 'angular2/src/facade/async';
|
|
import {ComponentInstruction} from './instruction';
|
|
|
|
export {
|
|
canReuse,
|
|
canDeactivate,
|
|
onActivate,
|
|
onReuse,
|
|
onDeactivate
|
|
} from './lifecycle_annotations_impl';
|
|
|
|
/**
|
|
* Defines route lifecycle hook `CanActivate`, which is called by the router to determine
|
|
* if a component can be instantiated as part of a navigation.
|
|
*
|
|
* <aside class="is-right">
|
|
* Note that unlike other lifecycle hooks, this one uses an annotation rather than an interface.
|
|
* This is because the `CanActivate` function is called before the component is instantiated.
|
|
* </aside>
|
|
*
|
|
* The `CanActivate` hook is called with two {@link ComponentInstruction}s as parameters, the first
|
|
* representing the current route being navigated to, and the second parameter representing the
|
|
* previous route or `null`.
|
|
*
|
|
* ```typescript
|
|
* @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 {@link OnActivate} hook of that component is called if implemented.
|
|
*
|
|
* ### Example
|
|
*
|
|
* {@example router/ts/can_activate/can_activate_example.ts region='canActivate' }
|
|
*/
|
|
export var CanActivate: (hook: (next: ComponentInstruction, prev: ComponentInstruction) =>
|
|
Promise<boolean>| boolean) => ClassDecorator =
|
|
makeDecorator(CanActivateAnnotation);
|