简体   繁体   English

如何从应用路由模块获取路由?

[英]How to fetch routes from app-routing module?

I'm still learning angular so I'm not very comfortable with it yet.我还在学习 angular 所以我还不太适应。 My question is the following: is there any way of fetching my routes array from app-routing.module.ts?我的问题如下:有没有办法从 app-routing.module.ts 中获取我的路由数组? Because I want to have a mat-tab-navbar with the routes I defined but in a specified component(not in app-component only), since I'm getting the error below:因为我想要一个带有我定义但在指定组件中的路由的 mat-tab-navbar(而不是仅在 app-component 中),因为我收到以下错误:

Maybe there is a better solution that you could provide?也许您可以提供更好的解决方案? Thanks in advance!提前致谢!

在此处输入图像描述

If you want to get those routes defined in the app.module you can use如果您想获取 app.module 中定义的那些路由,您可以使用

constructor(private router: Router) { }

ngOnInit() {
  this.routes = this.router.config;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM