Answer the question
In order to leave comments, you need to log in
How to set up Angular2+Webpack asynchronous routing?
Recently started working with webpacko. And still I can not teach him to accept my asynchronous routing. There is a working example in the standard build:
@RouteConfig([
{ path: '/', name: 'Index', component: Home, useAsDefault: true },
{ path: '/home', name: 'Home', component: Home },
// Async load a component using Webpack's require with es6-promise-loader and webpack `require`
{ path: '/about', name: 'About', loader: () => require('es6-promise!./about/about')('About') },
])
import {Component} from 'angular2/core';
console.log('`About` component loaded asynchronously');
@Component({
selector: 'about',
template: `<h1>Bla-bla-bla</h1>`
})
export class About {
constructor() {
}
ngOnInit() {
console.log('hello `About` component');
}
}
Answer the question
In order to leave comments, you need to log in
require('es6-promise!./about/about')('About')
Let's try to figure it out. We go to the documentation for the webpack .
Those. this construct require('es6-promise!./about/about')
is a call to load the module using an overridden loader, and not just a loader that is registered in the webpack.config.js of this assembly
loaders: [
// See: https://github.com/s-panferov/awesome-typescript-loader
{test: /\.ts$/, loader: 'awesome-typescript-loader', exclude: [/\.(spec|e2e)\.ts$/]},
ngOnInit() {
console.log('hello `About` component');
}
from component
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question