Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RouterModule.forRoot() in Angular2 compiler/cli ngc command

Let's say i have the following appRoutingModule:

export const routes: Route[] = [
  {
    path: '',
    component: ApplicationlistComponent
  }
];

@NgModule( {
  imports: [ ApplicationsModule, RouterModule.forRoot( routes ) ],
  exports: [ RouterModule ],
  declarations: [ApplicationlistComponent]
} )
export class AppRoutingModule {
}

When compiling this with the ngc cli command it will give the following error:

Error: Error encountered resolving symbol values statically. Calling function 'RouterModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts

I tried putting it inside an exported const:

export const routerModule =  RouterModule.forRoot( routes );

But that will give this error:

Error: Error encountered resolving symbol values statically

What is the workaround/fix to get this working? How do i define my routes if i can't pass it to the RouterModule?

I'm using versions:

"@angular/compiler": "~2.4.0",
"@angular/compiler-cli": "~2.4.0",
"@angular/platform-server": "~2.4.0",
"@angular/router": "~3.4.0"

etc.

like image 634
Piet K Avatar asked Oct 18 '22 19:10

Piet K


1 Answers

I resolved this by reverting angular back to version 2.3.1. Looks like it's broken in the 2.4.0 release..

like image 159
Piet K Avatar answered Oct 21 '22 02:10

Piet K