import {bootstrap, Component, bind} from 'angular2/angular2'; import { CanActivate, RouteConfig, ComponentInstruction, ROUTER_DIRECTIVES, APP_BASE_HREF, CanReuse, RouteParams, OnReuse } from 'angular2/router'; // #docregion reuseCmp @Component({ selector: 'my-cmp', template: `
hello {{name}}!
message:
` }) class MyCmp implements CanReuse, OnReuse { name: string; constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; } canReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; } onReuse(next: ComponentInstruction, prev: ComponentInstruction) { this.name = next.params['name']; } } // #enddocregion @Component({ selector: 'example-app', template: `

Say hi to...

Naomi | Brad `, directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/', component: MyCmp, as: 'HomeCmp'}, {path: '/:name', component: MyCmp, as: 'HomeCmp'} ]) class AppCmp { } export function main() { return bootstrap(AppCmp, [bind(APP_BASE_HREF).toValue('/angular2/examples/router/ts/reuse')]); }