CanDeactivate

export interface CanDeactivate

exported from angular2/router defined in angular2/src/router/interfaces.ts (line 94)

Defines route lifecycle method routerCanDeactivate, which is called by the router to determine if a component can be removed as part of a navigation.

The routerCanDeactivate 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.

If routerCanDeactivate returns or resolves to false, the navigation is cancelled. If it returns or resolves to true, then the navigation continues, and the component will be deactivated (the OnDeactivate hook will be run) and removed.

If routerCanDeactivate throws or rejects, the navigation is also cancelled.

Example

@Component({ selector: 'note-cmp', template: ` <div> <h2>id: {{id}}</h2> <textarea cols="40" rows="10"></textarea> </div>` }) class NoteCmp implements CanDeactivate { id: string; constructor(params: RouteParams) { this.id = params.get('id'); } routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) { return confirm('Are you sure you want to leave?'); } }

Members

routerCanDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction) : any

Not Yet Documented