我正試圖在我的示例angular2應用程序中實現延遲加載功能模塊。無法在Angular2中延遲加載模塊(RC-6)
我的應用程序有一個根模塊和兩個功能模塊。
和路由根模塊的路徑文件是功能模塊的
app/public/scripts/app.module.ts
app/public/scripts/app.routing.ts
路徑,並將它的路由爲此,我要實現延遲加載是
app/public/scripts/modules/user/app.user.module.ts
app/public/scripts/modules/user/app.user.routing.ts
下面是app.routing.ts代碼
'use strict';
import {Routes , RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
const appRoutes : Routes = [
{path: 'ausers' , loadChildren: 'scripts/modules/user/app.users.module#UsersModule' }
];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
下面是app.user.routing.ts代碼
'use strict';
import { ModuleWithProviders } from '@angular/core';
import { Routes , RouterModule } from '@angular/router';
//-- import components , directives and pipes
import { AppUsersComponent } from './app.users.component';
const UserRoutes :Routes = [
{path: 'ausers/showusers' , component: AppUsersComponent }
]
export const userRouting: ModuleWithProviers = RouterModule.forChild(UserRoutes);
當用戶點擊下面聯繫在應用
routerLink = 「ausers/showusers」
它顯示以下錯誤
Failed to parse SourceMap: http://localhost:3000/scripts/BehaviorSubject.js.map Angular 2 is running in the development mode. Call >enableProdMode() to enable the production mode. EXCEPTION: Uncaught (in promise): Error: SyntaxError: Unexpected >token < Evaluating http://localhost:3000/scripts/modules/user/app.users.module Error loading http://localhost:3000/scripts/modules/user/app.users.module
我使用加載模塊和捆紮的WebPack。
任何想法可能是這個錯誤的原因是什麼?
那是唯一的錯誤消息?無論如何..子路線是相對的..所以請將您的子路線從'ausers/showusers'改爲'showusers'。 – mxii
更改路徑沒有幫助,更新了有關錯誤 – refactor
@ j2L4e的更多信息,您在此鏈接中提供的解決方案正常工作。 – refactor