如何使用新的NavigationStart @ angular-router 3.0.0-alpha.* [英] How to use new NavigationStart @angular-router 3.0.0-alpha.*

查看:67
本文介绍了如何使用新的NavigationStart @ angular-router 3.0.0-alpha.*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新的Angular 2 Router中看到了这些新事件.

I see these new events in the new Angular 2 Router.

有NavigationStart,NavigationEnd,NavigationFailed(或类似的东西)

Theres NavigationStart, NavigationEnd, NavigationFailed (or something like that)

有人知道如何使用这些吗?我搞砸了几件事,但还没能使他们做任何事情.

Does anyone know how to use these yet? I've messed around with a few things but haven't been able to get them to do anything.

推荐答案

Router提供了一个可订阅的events可观察对象

The Router provides an events observable that can be subscribed to

constructor(router:Router) {
  router.events.subscribe(event => {
    if(event instanceof NavigationStart) {
    }
    // NavigationEnd
    // NavigationCancel
    // NavigationError
    // RoutesRecognized
  }
});

另请参见

  • https://angular.io/docs/ts/latest/api/router/index/Router-interface.html
  • https://angular.io/docs/ts/latest/api/router/index/NavigationStart-class.html
  • https://angular.io/docs/ts/latest/api/router/index/NavigationEnd-class.html
  • https://angular.io/docs/ts/latest/api/router/index/NavigationCancel-class.html
  • https://angular.io/docs/ts/latest/api/router/index/NavigationError-class.html
  • https://angular.io/docs/ts/latest/api/router/index/RoutesRecognized-class.html

注意

不要忘记从router模块导入NavigationStart

import { Router, NavigationStart } from '@angular/router';

因为如果不导入它,则instanceof将不起作用,并且会出现错误NavigationStart is not defined.

because if you don't import it instanceof will not work and an error NavigationStart is not defined will rise.

这篇关于如何使用新的NavigationStart @ angular-router 3.0.0-alpha.*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆