我有一个角度2应用程序,并希望拦截路线事件,防止它们发生,播放动画,然后继续路由.
我的想法是这样的
如果我有课
export class SomeComponent { constructor(private router: Router){ router.events.subscribe(evt => { if(evt instanceof NavigationStart){ //I would like to cancel the event here the first time,and then //play an animation,after the animation is done,trigger the router //to go to the original route it wanted to. } }) } }
有没有办法阻止该路由器完成导航过程?
您可以为父路径创建CanActivate防护,您可以根据某些全局变量停止导航.变量可以具有基于动画是否已显示的值.
所以你可能会做的是,
export class AnimationGuard implements CanActivate { canActivate(route: ActivatedRouteSnapshot,state: RouterStateSnapshot) { if(HasAnimationRun){ return true; } runAnimation(state.url); return false; } } runAnimation(url){ // run animation // set global variable. // navigate to url }
了解有关CanActivate here的更多信息.
希望这可以帮助!!
原文地址:https://www.jb51.cc/angularjs/140288.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。