加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

typescript – 如何使用新的NavigationStart @ angular-router 3

发布时间:2020-12-17 09:29:16 所属栏目:安全 来源:网络整理
导读:我在新的Angular 2路由器中看到这些新的事件. Theres NavigationStart,NavigationEnd,NavigationFailed(或类似的东西) 有人知道如何使用这些吗?我已经搞砸了几件事,但是还是无法让他们做任何事情. 路由器提供可以订阅的事件observable constructor(router:R
我在新的Angular 2路由器中看到这些新的事件.

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

有人知道如何使用这些吗?我已经搞砸了几件事,但是还是无法让他们做任何事情.

路由器提供可以订阅的事件observable
constructor(router:Router) {
  router.events.subscribe(event: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

注意

不要忘记从路由器模块导入NavigationStart

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

因为如果不导入它,instanceof将不起作用,并且未定义的NavigationStart错误将会上升.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读