title: Angular 2: How to apply a callback when I leave a route
body: <p>Here is the example, I have some routes defined in <code>AppComponent</code>:</p>
  
  <pre><code>@RouteConfig([
    {path:'/',         name: 'Index', component: IndexComponent, useAsDefault: true},
    {path:'/:id/...',  name: 'User',  component: UserComponent},
    {path:'/plan',     name: 'Plan',  component: PlanComponent},
    {path:'/foo',      name: 'Foo',   component: FooComponent}
  ]}
  </code></pre>
  
  <p>and in <code>UserComponent</code> I have another route defined like this :</p>
  
  <pre><code>@RouteConfig([
    {path:'/info',   name: 'UserInfo',   component: UserInfoComponent, useAsDefault: true},
    {path:'/order',  name: 'UserOrder',  component: UserOrderComponent},
    {path:'/detail', name: 'UserDetail', component: UserDetailComponent}
  ]}
  </code></pre>
  
  <p>There are 2 separate navigations defined in both <code>AppComponent</code> and <code>UserComponent</code>:</p>
  
  <pre><code>//AppComponent:
    &lt;a [routerLink]="['User']"&gt;User&lt;/a&gt;
    &lt;a [routerLink]="['Plan']"&gt;Plan&lt;/a&gt;
    &lt;a [routerLink]="['Foo']"&gt;Foo&lt;/a&gt;
  --------------------------------------------
  //UserComponent:
    &lt;a [routerLink]="['UserInfo']"&gt;User Info&lt;/a&gt;
    &lt;a [routerLink]="['UserOrder']"&gt;User Order&lt;/a&gt;
    &lt;a [routerLink]="['UserDetail']"&gt;User Detail&lt;/a&gt;
  </code></pre>
  
  <p>The behavior I expect is:<br/>
  When user click on these navigations, a modal will comes up and ask user if he confirm to save before leaving this route. if yes, save the user's change automatically.</p>
  
  <p>Since it seems that there is no way to get these changes in <code>UserComponent</code>, I want to put the logic into these child components (<code>UserInfoComponent</code>, <code>UserOrderComponent</code> and <code>UserDetailComponent</code>). So is there any way I can trigger a callback when user leave the current route inside the child component? if not, is there any alternative way to achieve that? Thanks</p>