本文介绍了angular2 $ routeChangeStart,$ routeChangeSuccess,$ routeChangeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在angular2中,这些angular1事件的等效项是什么?

In angular2 what is the equivalent of these angular1 events?

$ routeChangeStart,$ routeChangeSuccess,$ routeChangeError

$routeChangeStart , $routeChangeSuccess ,$routeChangeError

我想在根应用程序组件中使用这些事件来处理任何路由更改.

I want to use these events in root app component to deal with any route changing.

预先感谢

更新

  • 如果我使用OnActivate,OnDeactivate事件,则需要将其添加到每个组件中:(

  • If i use OnActivate, OnDeactivate events, it needs to add it to every component :(

我也尝试实现自己的RouterOutlet,但是我无法访问先前关于激活,停用事件的指令,而且我也不知道如何处理路由更改错误

Also i tried to implement my own RouterOutlet but i can't access previous instruction on activate, deactivate events, also i don't know how to handle the route Change Error

也router.subscribe只给了我名字,但我想获取当前和下一个指令对象来更改某些属性

Also router.subscribe gave me the name only but i want to get the current and next instruction objects to change some properties

我的目标是:

1-在开始更改页面时显示加载指示器,并在页面加载时将其隐藏.

1- Show loading indicator when start change page and hide it on page load.

2-为当前和下一条指令制作过渡动画rtl或ltr

2- Make transition animation rtl or ltr for current and next instruction

推荐答案

有一些事件,例如 OnActivate OnDeactivate 和保护功能 CanActivate 和您可以查看的 CanDeactivate .

There are some events such as OnActivate, OnDeactivate and guard functions CanActivate and CanDeactivate that you can look at.

请参阅路由器

这篇关于angular2 $ routeChangeStart,$ routeChangeSuccess,$ routeChangeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:49