import {APP_BASE_HREF} from '@angular/common'; import {Component, ComponentRef, provide} from '@angular/core'; import {bootstrap} from '@angular/platform-browser-dynamic'; import {CanDeactivate, ComponentInstruction, ROUTER_DIRECTIVES, RouteConfig, RouteParams} from '@angular/router-deprecated'; // #docregion routerCanDeactivate @Component({ selector: 'note-cmp', template: `

id: {{id}}

` }) 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?'); } } // #enddocregion @Component({ selector: 'note-index-cmp', template: `

Your Notes

Edit Note 1 | Edit Note 2
`, directives: [ROUTER_DIRECTIVES] }) class NoteIndexCmp { } @Component({ selector: 'example-app', template: `

My App

`, directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/note/:id', component: NoteCmp, name: 'NoteCmp'}, {path: '/', component: NoteIndexCmp, name: 'NoteIndexCmp'} ]) export class AppCmp { } export function main(): Promise> { return bootstrap( AppCmp, [{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/can_deactivate'}]); }