CanReuse

export interface CanReuse

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

Defines route lifecycle method routerCanReuse, which is called by the router to determine whether a component should be reused across routes, or whether to destroy and instantiate a new component.

The routerCanReuse 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 routerCanReuse returns or resolves to true, the component instance will be reused and the OnDeactivate hook will be run. If routerCanReuse returns or resolves to false, a new component will be instantiated, and the existing component will be deactivated and removed as part of the navigation.

If routerCanReuse throws or rejects, the navigation will be cancelled.

Example

@Component({ selector: 'my-cmp', template: ` <div>hello {{name}}!</div> <div>message: <input id="message"></div> ` }) class MyCmp implements CanReuse, OnReuse { name: string; constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; } routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; } routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) { this.name = next.params['name']; } }

Members

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

Not Yet Documented