Angular 7路由动画只能运行一次。
创始人
2024-10-17 02:30:47
0

要解决Angular 7路由动画只能运行一次的问题,你可以尝试以下代码示例中的解决方法:

  1. 在app.module.ts中导入BrowserAnimationsModule:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  imports: [
    BrowserAnimationsModule
  ],
  ...
})
export class AppModule { }
  1. 在组件中定义动画:
import { trigger, transition, style, animate } from '@angular/animations';

@Component({
  ...
  animations: [
    trigger('routeAnimations', [
      transition('HomePage <=> AboutPage', [
        style({ position: 'relative' }),
        query(':enter, :leave', [
          style({
            position: 'absolute',
            top: 0,
            left: 0,
            width: '100%'
          })
        ]),
        query(':enter', [
          style({ left: '-100%' })
        ]),
        query(':leave', animateChild()),
        group([
          query(':leave', [
            animate('300ms ease-out', style({ left: '100%' }))
          ]),
          query(':enter', [
            animate('300ms ease-out', style({ left: '0%' }))
          ])
        ]),
        query(':enter', animateChild()),
      ]),
      transition('* <=> FilterPage', [
        // Define your animation for other routes
      ])
    ])
  ]
})
export class AppComponent { }
  1. 在HTML模板中应用动画:
  1. 在组件中定义getRouteAnimation方法:
import { RouterOutlet } from '@angular/router';

@Component({ ... })
export class AppComponent {
  getRouteAnimation(outlet: RouterOutlet) {
    return outlet.activatedRouteData.animation;
  }
}
  1. 在路由模块中定义动画数据:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomePageComponent, data: { animation: 'HomePage' } },
  { path: 'about', component: AboutPageComponent, data: { animation: 'AboutPage' } },
  { path: 'filter', component: FilterPageComponent, data: { animation: 'FilterPage' } },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

通过以上步骤,你应该能够解决Angular 7路由动画只能运行一次的问题,并使动画在每次路由导航时都能正常运行。

相关内容

热门资讯

一起来探讨!wepoker好友... 此外,数据分析德州(wepoker好友房开挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户w...
科技介绍!pokemmo脚本辅... 科技介绍!pokemmo脚本辅助器,wepoker数据分析工具,微扑克教程(有挂教程)准备好在wep...
重磅来袭!aapoker透视脚... 重磅来袭!aapoker透视脚本下载,wepoker私人定制透视,介绍教程(有挂方法)是一款可以让一...
发现玩家!aapoker怎么开... 《发现玩家!aapoker怎么开辅助器,sohoo poker辅助器,玩家教程(有挂技巧)》 aap...
技巧知识分享!wepoker辅... 技巧知识分享!wepoker辅助插件功能,hhpoker辅助挂,新版2025教程(有挂透明)关于we...
总算清楚!wepoker可以透... 总算清楚!wepoker可以透视码,we-poker辅助软件教程,必备教程(有挂技巧)1、点击下载安...
重大通报!wepoker底牌透... 1、重大通报!wepoker底牌透视,拱趴大菠萝有挂吗,必赢方法(有挂软件);详细教程。2、拱趴大菠...
推荐十款!wepoker国外版... 此外,数据分析德州(wepoker怎么挂底牌)辅助神器app还具备辅助透视行为开挂功能,通过对客户w...
揭秘!wepoker透视脚本是... 揭秘!wepoker透视脚本是什么,werplan怎么作弊,透明挂教程(有挂透明)1、点击下载安装,...
今日焦点!智星菠萝可以辅助吗,... 今日焦点!智星菠萝可以辅助吗,wepoker私局辅助,普及教程(有挂透视)1、点击下载安装,微扑克w...