我尝试在angular2 / 4路由中加载到子模块,但我得到了错误:
错误:未捕获(在承诺中):错误:找不到模块 '../市场就地/市场place.module'。
我尝试了以下代码父路由 discover.routing.ts :
import { RouterModule, Routes } from '@angular/router';
const DiscoverRoutes: Routes = [
// part of MarketPlace
{
path: 'market-place', loadChildren: '../market-place/market-place.module#MarketPlaceModule',
}
]
export const DiscoversRoutes = RouterModule.forChild(DiscoverRoutes);
在html中:
<a [routerLink]=" ['discoverd/market-place'] ">Market place</a>
更新
父模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DiscoversRoutes } from './discover.routing';
import { DiscoverComponent } from './discover.component'
@NgModule({
imports: [
CommonModule,
DiscoversRoutes
],
declarations: [
DiscoverComponent
],
})
export class DiscoverModule { }
子路由模块
{ path: '', redirectTo: 'vendors', pathMatch: 'full' },
{
path: '',
component: MarketPlaceComponent,
children: [
{ // Vendors selection
path: 'vendors',
component: MpVendorSelectionComponent,
canActivate: [AuthGuardService],
resolve: { partner: PartnerResolver },
data: { roles: ['products.list_vendordetails'] }
}]
}}
export const MarketPlaceRouting = RouterModule.forChild(MarketPlaceRoutes);
子模块:
import { NgModule } from '@angular/core';
import { SharedModule } from 'app/shared';
import { CommonModule } from '@angular/common';
import { MarketPlaceRouting } from './market-place.routing';
import { RouterModule } from '@angular/router';// Components
import { MarketPlaceComponent } from './market-place.component';
import { MpVendorSelectionComponent } from './mp-vendor-selection/mp-vendor-selection.component';
import { MpProductsSelectionComponent } from './mp-products-selection/mp-products-selection.component';
import { MpProductsListComponent } from './mp-products-selection/mp-products-list/mp-products-list.component';
import { MpProductViewComponent } from './mp-products-selection/mp-product-view/mp-product-view.component';
@NgModule({
imports: [
CommonModule,
SharedModule,
MarketPlaceRouting
],
declarations: [
MarketPlaceComponent,
MpVendorSelectionComponent,
MpProductsSelectionComponent,
MpProductsListComponent,
MpProductViewComponent,
],
providers: [
]
})
export class MarketPlaceModule { }
感谢advnace