我想获取当前模块的所有延迟加载的路由。但是,无论我尝试了什么,我都没有让孩子们离开。这些路由在_loadedConfig.routes
中可用,但我无法访问。
这是我的设置:
app-routing-module.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{path: 'button', loadChildren: './pages/button/button.module#ButtonModule'},
{path: '', redirectTo: 'action-sheet', pathMatch: 'full'}
]
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
我要在其中获取所有延迟加载路由的组件:
import { Component, OnInit } from "@angular/core";
import { Router, ChildActivationEnd } from "@angular/router";
@Component({
selector: "button-component",
templateUrl: "./button.component.html",
styleUrls: ["./button.component.scss"]
})
export class ButtonComponent implements OnInit {
constructor(private router: Router) {
}
ngOnInit() {
console.log(this.router.config); // I want to get the lazy loaded routes here
}
}
该组件的模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { RouterModule } from '@angular/router';
import { ButtonComponent } from './button.component';
import { ChildPageComponent } from './child-page/child-page.component'
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild([
{
path: '',
component: ButtonComponent
},
{
path: 'child-page',
loadChildren: './child-page/child-page.module#ChildPageModule',
}
])
],
declarations: [
ButtonComponent,
ChildPageComponent,
]
})
export class ButtonModule {}
我只想获得child-page
的路线。
Stackblitz示例(在路径/ button上): https://stackblitz.com/edit/ionic-v4-i17ztz