Angular2 router: how to correctly load children modules with their own routing rules

后端 未结 4 837
终归单人心
终归单人心 2020-12-08 06:45

here is my Angular2 app structure:

Here is part of my code. The following is the main module of the Angular2 app, that imports its routing rule

4条回答
  •  孤街浪徒
    2020-12-08 07:34

    Not sure if I get the problem correctly, but here is a small code snippet which I used to generate routes dynamically:

    app.component.ts:

    constructor(private _router: Router) {
    }
    
    ngOnInit() {
         ...
         this._router.config[0].children = myService.getRoutes(); 
         this._router.resetConfig(this._router.config);
         console.debug('Routes:', this._router.config);
         ...
    }
    

    It is not OOTB solution, but you can get information about current routes.

提交回复
热议问题