2

I try to implement router lazy loading in angular 2, so that I can do something like

const routes: Routes = [
 { path: '', redirectTo: '/home', pathMatch: 'full',
 { path: 'about', loadChildren: './+about/about.module#AboutModule' }
];

It requires set up like

webpack.config.js
loaders: [
{
    test: /\.ts$/,
    loaders: [
      ‘awesome-typescript-loader’, 
      ‘angular2-template-loader’, 
     ‘angular2-router-loader’]
    },
  ...
]

The problem is I am using Visual Studio 2015 ASP.NET Core Template Pack, which got completely different contents in webpack.config.js. How can I set up to make the lazy loading working?

Should I be using ASP.NET Core Template Pack in the long run for developing angular 2 applications? I am not sure whether ASP.NET Core Template Pack is the right path for me. Thanks

1 Answer 1

1

It turns out to be quite simple

const routes: Routes = [
{
    path: 'hero', loadChildren: () => {
        return Promise.resolve(require('./components/hero/hero.module')['HeroModule']);
    } }

];

rather than

const routes: Routes = [
{  path: 'hero', loadChildren: './components/hero/hero.module#HeroModule' }
]

The idea is coming from http://qiita.com/Quramy/items/e3e6d63a2b155aec2067

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.