如果在 Angular 11 中使用懒加载模块时,路由无法正常工作,则可能需要采取以下步骤来解决该问题。
{ path: '', loadChildren: () => import('./example/example.module').then(m => m.ExampleModule), runGuardsAndResolvers: 'always' }
import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators';
constructor(private router: Router) { this.router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe(() => { window.scrollTo(0, 0); }); }
这些步骤将确保路由在懒加载模块中正常工作。