0

I'm lost with my understanding, how to bring async module loading to run in latest angular-webpack-starter (RC4 with @angular/router 3.0.0-beta.2).

There is an example included, but it would be helpful to get more explanation, what to do and how this plays together.

What I did: - I exported my lazy component routes:

export const referenzRoutes: RouterConfig = [
  { path: '', component: Test3 },
  { path: 'testApp', component: TestApp },
]

then I imported and used the child routes in my parent component routes:

import {referenzRoutes} from "./+Referenz/referenz.routes";
export const routes: RouterConfig = [
  {...},
  {path: 'referenz', component: 'Referenz', canActivate: [ WebpackAsyncRoute ], 
  children: referenzRoutes},
]

and I defined async routes like this for every component:

export const asyncRoutes: AsyncRoutes = {
  'Referenz': require('es6-promise-loader!./+Referenz/referenz.component'),
  'TestApp': require('es6-promise-loader!./+Referenz/testApp/testApp.component'),
  'Test3': require('es6-promise-loader!./+Referenz/test3/test3.component'),
};

I get an error from browser_adapter.js:84 Cannot read property 'path' of undefined when I navigate to TestApp. What is the right way to do this?

I wonder also, if the component names for async loading have to be unique for the whole application?

westor
  • 1,426
  • 1
  • 18
  • 35

1 Answers1

0

See the following blog post AsyncRoute with Webpack

Implement the following code below

[
  new AsyncRoute({
      path: '/'
      , name: RouterService.CONTROL_CENTER_ROUTE
      , loader: () => new Promise((resolve: any) => {
          (<any>require).ensure(['control-center.component']
          , (require: any) =>
            resolve(require('control-center.component').ControlCenterComponent));
      })
      , useAsDefault: true
    })
  , new AsyncRoute({
    path: '/login'
    , name: RouterService.LOGIN_ROUTE
    , loader: () => new Promise((resolve: any) => {
        (<any>require).ensure(['login.component']
        , (require: any) =>
          resolve(require('login.component').LoginComponent));
    })
  })
];
jtzero
  • 2,204
  • 2
  • 25
  • 44
Michael JDI
  • 1,241
  • 5
  • 18
  • 30