我创建了一个带有延迟加载路由的 Angular 2 / Angular Universal 应用程序,如下所示:
{
path: 'home',
loadChildren: './+app/+home/home.module#HomeModule'
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
当我localhost
在浏览器中导航到时,它会重定向到/home
并且一切正常。但是每当我localhost/home
通过硬重新加载进入浏览器时,我的 Node.js 终端都会抛出一个错误:
EXCEPTION: Uncaught (in promise): ReferenceError: System is not defined
ReferenceError: System is not defined at
SystemJsNgModuleLoader.loadAndCompile (...@angular/core/bundles/core.umd.js:7151:20)
不过,它似乎正确地渲染了视图。
当我将路线更改为使用非延迟加载方式时,错误消失了:
{
path: 'home',
component: HomeComponent
}
但我想在我的应用程序中使用延迟加载。在我的 HTML 中,我使用 SystemJS 导入客户端应用程序:
<script>
System.import('./client.js')
.then(function(m) {
console.log("Welcome");
});
</script>
我的依赖:
"@angular/common": "2.1.2",
"@angular/compiler": "2.1.2",
"@angular/core": "2.1.2",
"@angular/forms": "2.1.2",
"@angular/http": "2.1.2",
"@angular/platform-browser": "2.1.2",
"@angular/platform-browser-dynamic": "2.1.2",
"@angular/router": "3.1.2",
"@angularclass/bootloader": "1.0.1",
"angular2-express-engine": "2.1.0-rc.1",
"angular2-template-loader": "0.6.0",
"angular2-universal": "2.1.0-rc.1",
"angular2-universal-polyfills": "2.1.0-rc.1"
我该如何解决这个问题?