Angular2: Configuration 'name' conflicts with existing route 'name'

后端 未结 1 1101
星月不相逢
星月不相逢 2020-12-10 08:53

I have some components of which one with dynamic routes.

the dynamic routes are added as,

let config = [];
for(let i = 0; i < this.pages.length; i++         


        
相关标签:
1条回答
  • 2020-12-10 09:46

    Check if the route exists before adding it

    for(let i = 0; i < this.pages.length; i++) {
      if(!router.registry.hasRoute(this.pages[i].name, UsersComponent)) {
        config.push({
          path: this.pages[i].slug, 
          name : this.pages[i].name, 
          component: PersonComponent,
          data : {
            name : this.pages[i].name,
            slug : this.pages[i].slug
          }
        });
      }
    }
    

    Plunker

    0 讨论(0)
提交回复
热议问题