angular 重置配置会重新渲染被调用的组件,

svmlkihl  于 2个月前  发布在  Angular
关注(0)|答案(2)|浏览(38)

哪个@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 )

  • 无响应*

还有其他要说的吗?

  • 无响应*
eivnm1vs

eivnm1vs1#

你好,你看过RouteReuseStrategy了吗?
那可能是你要找的东西!

hgqdbh6s

hgqdbh6s2#

我发现了一个问题!
在通过resetConfig重新定义路由器后,Angular会在第一次重新定义之后重新渲染所有依赖的路由。

相关问题