angular - 在 router.events 中获取事件路由数据

标签 angular typescript angular2-routing

如何在订阅的 router.events 中获取事件路由数据(如参数)?

不想订阅this.route.params!

// Catch any events in a certain component, where I subscribe to it!
this.router.events.subscribe(event =>
{ 
// The event object has only the url (when is NavigationStart/End), there is nothing useful for me


});

更新

我的问题不同,因为我不问如何对路由器事件使用react!

我询问如何在 router.events 中获取激活路由参数!

这肯定是不同的!

最佳答案

this.router.events.subscribe(event =>
{ 
  console.log(this.router.routerState.root);
  console.log(this.router.routerState.root.firstChild);
  console.log(this.router.routerState.root.firstChild && this.router.routerState.root.firstChild.firstChild);
});

关于angular - 在 router.events 中获取事件路由数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41496316/

相关文章:

node.js - 扩展 “named-routes” 的 Express JS 路由器 TypeScript 定义

javascript - 'router-outlet' 不是 Angular2 的已知元素

angular - HttpClient错误处理程序中的 Angular 调用自定义函数

typescript - 在 TypeScript 箭头函数中指定返回类型

javascript - 突出显示 Angular2 中嵌套 ngFor 元素的 [class.active]

typescript - 在 TypeScript 中返回类(= 类构造函数)的工厂函数

ES5 中的 Angular 2 路由?

tomcat - 将angular2项目部署到tomcat服务器后刷新问题?

Angular 2隐藏或显示子组件

angular - Angular 12 项目的 UI 框架