哪个@angular/*包是bug的来源?
router
这是个回归吗?
是的
描述
我有一个根路由模块
{
path: 'home',
loadChildren: () => import('./routes/home/home.module').then(m => m.HomeModule),
},
{
path: 'manage',
loadChildren: () => import('./routes/manage/manage.module').then(m => m.ManageModule),
},
{
path: 'search',
loadChildren: () => import('./routes/search/search.module').then(m => m.SearchModule),
},
{
path: 'admin',
loadChildren: () => import('./routes/admin/admin.module').then(m => m.AdminModule),
}
当我遇到问题时,子路由模块。
{
path: '',
component: ManageComponent,
children: [
{
path: 'my-files',
component: MyFilesComponent,
},
{
path: 'some-path',
component: SomeComponent,
},
],
}
我需要根据后端的响应添加一个新路由,该路由与相同的 SomeComponent
组件相关。
之后,当我从某个组件调用 resetConfig
方法时,每次当我从(例如)MenuComponent更改路由时,所有模块(ManageModule)都会重新渲染其依赖的组件。
...export class MenuComponent {
constructor(private router: Router) {
const routes = [
{
path: 'somePath/:id/:child1/:child2',
component: SomeComponent,
},
{
path: 'somePath/:id/:child1',
component: SomeComponent,
},
{
path: 'somePath/:id/',
component: SomeComponent,
},
];
this.router.config.find(v => v.path === 'manage')._loadedRoutes[0].children.push(...routes);
this.router.resetConfig(this.router.config);
}
}
<a [routerLink]="['./some-path']">Some Path</a>
<a [routerLink]="['./my-files']">My Files</a>
我不知道还有其他什么方式来解释。如果需要的话,我可以提供一个示例
请提供一个链接,指向最小复现bug的情况
- 无响应*
请提供您看到的异常或错误
- 无响应*
请提供您发现此bug的环境(运行 ng version
)
- 无响应*
还有其他要说的吗?
- 无响应*
2条答案
按热度按时间eivnm1vs1#
你好,你看过RouteReuseStrategy了吗?
那可能是你要找的东西!
hgqdbh6s2#
我发现了一个问题!
在通过
resetConfig
重新定义路由器后,Angular会在第一次重新定义之后重新渲染所有依赖的路由。