To ensure that the proc animation is routed on each route, you will need to define the transitions between each route. The following is an example that I use to create a box effect when switching between my "home" route and my "acct" route:
import { trigger, animate, style, group, query, transition } from '@angular/animations';
export const baseAnimation =
trigger('baseAnimation', [
transition('acct => home', [
query(':enter, :leave', style({ position: 'absolute', top: 0, left: 0, right: 0 })),
query(':leave', style({ height: '*'})),
query('.acct', [
animate('300ms',
style({ height: 0 }))
])
]),
transition('home => acct', [
query(':enter, :leave',
style({ position: 'absolute', top: 0, left: 0, right: 0 })),
query(':enter .acct', [
style({ height: 0 }),
animate('300ms', style({ height: '*' }))
])
])
])
, .acct ( ). , .
app.component.html :
<div [@baseAnimation]="prepareRouteTransition(outlet)">
<router-outlet #outlet="outlet"></router-outlet>
</div>
</div>
app.component.ts :
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { baseAnimation } from './anim/base.animation';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
animations: [ baseAnimation ]
})
export class AppComponent {
constructor() { }
prepareRouteTransition(outlet) {
const animation = outlet.activatedRouteData['animation'] || {};
return animation['value'] || null;
}
}