对于页面转换,您可以依赖routeAnimation
Animations.ts
import {style, animate, transition, state, trigger} from '@angular/core';
export default [
trigger('routeAnimation', [
state('*', style({opacity: 1, height: '100%'})),
transition('void => *', [
style({opacity: 0, height: '100%'}),
animate(200)
]),
transition('* => void', animate(0, style({opacity: 0, height: '100%'})))
])
];
然后在你的YourComponent.ts
import animations from './Animations';
@Component({
...
animations: animations
})
export class YourComponent {
@HostBinding('@routeAnimation') public routeAnimation:void;
...
}
可选:这假设您的routing.ts
文件看起来像
import {RouterModule} from '@angular/router';
import {ModuleWithProviders} from '@angular/core';
import {YourComponent} from './YourComponent';
export const routing:ModuleWithProviders = RouterModule.forChild([
{path: "aPath", component: YourComponent}
]);