angular - Angular routing animation: Plays once on refresh
问题描述
I'm trying to adding a sliding transitions between different pages via a button click but the animation will only play when i either refresh the page or type the address in the url.
BrowserAnimationModules is imported and tried putting the router outlet tag outside of the app-main-nav still creates the same problem.
animations.ts
export const slider =
trigger('routeAnimations', [
transition('* => isLeft', slideTo('left') ),
transition('* => isRight', slideTo('right') ),
transition('isRight => *', slideTo('left') ),
transition('isLeft => *', slideTo('right') )
]);
function slideTo(direction) {
const optional = { optional: true };
return [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
[direction]: 0,
width: '100%'
})
], optional),
query(':enter', [
style({ [direction]: '-100%'})
]),
group([
query(':leave', [
animate('800ms ease', style({ [direction]: '100%'}))
], optional),
query(':enter', [
animate('800ms ease', style({ [direction]: '0%'}))
])
]),
// query(':leave', animateChild()),
// query(':enter', animateChild()),
];
}
app.component.ts
prepareRoute(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
}
app.component.html
<app-main-nav>
<div [@routeAnimations]="prepareRoute(outlet)" style="position: relative;">
<router-outlet #outlet="outlet"></router-outlet>
</div>
</app-main-nav>
The routes should play a sliding animation when a button is pressed. The animation only plays when the page is refreshed
解决方案
就我而言,错误是我将导航返回按钮放到了表单上。因此,当我想返回时,它触发了表单并重新加载了页面。
推荐阅读
- django - Django 单元测试故障转移域套接字
- php - 如何在 smarty 中获取数组的特殊名称的值?
- r - 课程日期 x 轴上的 ggplot geom_vline
- xml - Shopify 商店 - 在成功页面上将订单详细信息上传到远程服务器
- html - 删除旁边的标签
- python - 如何使用 Flask 接收 excel 文件作为输入并使用 openpyxl 读取它?
- git - Git pre-commit/pre-push hook 在提交时运行单元测试,在工作树上进行未提交的更改
- c++ - 你能用参数制作一个函数向量吗?
- node.js - 如何通过 parse / back4app 使用会话?
- ios - 什么是 AuthStateDidChangeListenerHandle?