简体   繁体   中英

Is there a way to build a dynamic navigation/menu based on registered routes in Angular 2?

I'm currently struggling to find a way to build a dynamic navigation based on routes registered in the application.

As far as I see there is no simple way to get a list of all routes using Router or RouteRegistry classes.

But, there is a private _rules property inside of RouteRegistry class, but unfortunately with no getter for it.

Is there any specific reason why I can't access this parameter outside the RouteRegistry?

Any help would be appreciated.

You can store the routes in an array outside of the component so you can pass it to @RouteConfig(...) and also load into your component and analyze it to generate the menu.

The router is currently reworked therefore things that currently aren't that easy might become better soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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