我正在尝试对 Angular 4.0.1 中的每个路由转换进行淡入/淡出。我看过无数的“滑入/滑出”教程,但这些对我没有用。
这是我的 app.component
零件:
@Component({
selector: 'app',
templateUrl: 'app.component.html',
animations: [trigger('RouterAnimation', [
state('void', style({opacity:0}) ),
state('*', style({opacity:1}) ),
transition(':enter', [
style({opacity: 0}),
animate(2000, style({opacity: 1})),
]),
transition(':leave', [
style({opacity: 1}),
animate(1000, style({opacity: 0})),
])
])],
host: {'[@RouterAnimation]': 'true'}
})
HTML:
<notification></notification>
<div class="page-wrapper">
<login-register></login-register>
<app-header></app-header>
<sub-header></sub-header>
<router-outlet></router-outlet>
<router-outlet name="popup"></router-outlet>
<app-footer></app-footer>
</div>
上面的代码不起作用,@RouterAnimation 是否应该是可变的并在组件加载时发生变化?
应用程序中的所有路由都由自定义路由服务(Router 的包装器)处理,我可以在每次 url 更改发生时向 app.component 发送广播,并延迟路由(:leave 转换的时间)?
我可以在 app-routing.module 中指定我想在哪里使用动画吗?
有谁知道这应该如何工作?或者在 Angular 4.0.1 中有一个具有复杂路由的工作示例(儿童而不使用 routerlink)