Search code examples
angularangular-routingangular-routerangular9

Cannot redeclare block-scoped variable 'AppRoutes'


I am trying to achieve my angular application route to split in to 3 clear part.

  1. App-Router Module => let it load the app scope module routes. ( at present i have 1 scope as "setup-config )
  2. let Scope-Module take care of feature modules. ( at present i have 2 feature modules )

  3. let the feature module take care of it's own feature components.

the reason to clarity and rescablility i am trying to achieve this. but getting an error as "Cannot redeclare block-scoped variable 'AppRoutes'."

Any one help me to sort this issue? if the way what i try is wrong, can any one please show me the correct way to achieve this?

Here is the live demo


Solution

  • You have AppRoutes declared twice in your file. You should probably name one appRoutes:

    const appRoutes: Routes = [{
      path:"",
      pathMatch:"full",
      loadChildren:() => import('./setup-config/setup-config.module').then(m => m.ScopeModule)
    }]
    
    @NgModule({
      declarations: [],
      imports: [
        CommonModule,
        ScopeModule,
        RouterModule.forRoot(appRoutes, { 
          scrollPositionRestoration: 'enabled',
          useHash: true
        })
      ],
      exports: []
    })
    export class AppRoutes {}
    

    working stackblitz

    working one with routing