Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consider replacing the function or lambda with a reference to an exported function angular CLI

I just updated my project to Angular-CLI and I am on:

"@angular/cli": "1.0.0",
    "@angular/compiler-cli": "4.0.1",

I am getting an error saying:

Consider replacing the function or lambda with a reference to an exported function angular CLI

from this .ts file:

userManagement/userManagement.routing.ts

import {RouterModule, Routes} from "@angular/router";

export const routes: Routes = [
    {
        path: '', redirectTo: 'unlockUserID', pathMatch: 'full'
    },
    {
        path: 'unlockUserID',
        loadChildren: ()=> System.import('./unlockUserID/unlockUserID.module')
            .then((imports: any)=> imports.UnlockUserIdModule)
    },
    {
        path: 'changePassword',
        loadChildren: ()=> System.import('./changePassword/changePassword.module')
            .then((imports: any)=> imports.ChangePasswordModule)
    },
    {
        path: 'maintainOfficeHierarchy',
        loadChildren: ()=> System.import('./maintainOfficeHierarchy/maintainOfficeHierarchy.module')
            .then((imports: any)=> imports.MaintainOfficeHierarchyModule)
    },
];

export const routing = RouterModule.forChild(routes);

Than in my module:

@NgModule({

    imports: [
        SmartadminModule,
        routing,
    ],
    providers: [],
})
export class UserManagementModule {

}

--------------------------------Update 1-----------------------------

Had to change it to this:

export const routes: Routes = [
    {
        path: '', redirectTo: 'unlockUserID', pathMatch: 'full'
    },
    {
        path: 'unlockUserID',
        loadChildren: './unlockUserID/unlockUserID.module',
        data: {pageTitle: 'unlockUserID'}
    },
    {
        path: 'changePassword',
        loadChildren: './changePassword/changePassword.module',
        data: {pageTitle: 'changePassword'}
    },
export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {useHash: true});

Now I am getting the following error:

Error: RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.

---------------------------Update 2---------------------------

I changed it to

export const routing: ModuleWithProviders = RouterModule.forChild(routes);

Now I am getting an error saying:

 Cannot find 'default' in './changePassword/changePassword.module'

If I click on the changePassword tab, same for the other links.

like image 557
Mike3355 Avatar asked May 07 '26 22:05

Mike3355


1 Answers

According to https://github.com/rangle/angular-2-aot-sandbox#arrow-function-exports-top

Arrow function does not work with AoT when it is passed to an NgModule.

So you shouldn't define Arrow functions inside your Routes.

like image 143
eko Avatar answered May 10 '26 21:05

eko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!