Angular 具有延迟加载模块的嵌套路由器插座
Angular Nested Router Outlets with Lazy Loaded Modules
我正在尝试在另一个路由器插座内创建一个路由器插座以用作子导航,但尝试了以下方法但它不起作用
主页组件:
<router-outlet></router-outlet>
MainRouting/AppRouting:
const routes: Routes = [
{ path: '', component: HomeComponent},
{ path: 'properties', loadChildren: () => import(`./properties/properties.module`).then(m => m.propertiesModule)}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class MainRoutingModule { }
PropertiesComponent
<button [routerLink]="[{ outlets: { properties: ['searchproperties'] } }]">Search Properties</button>
<router-outlet name="properties"></router-outlet>
PropertiesRouting:
const routes: Routes = [
{ path: '', component: PropertiesComponent},
{ path: 'searchproperties', loadChildren: () => import(`./searchproperties/searchproperties.module`).then(m => m.SearchpropertiesModule), outlet: "properties"},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PropertiesRouting { }
只需在您的属性组件中添加您的路由器插座
<!--properties.component.html-->
<button [routerLink]="[{ outlets: { properties: ['searchproperties'] } }]">
Search Properties
</button>
<router-outlet></router-outlet>
<!--no name on routerOutlet-->
然后在您的属性模块路由中,在默认路由中配置 PropertiesComponent,并将您的 SearchComponent 配置为该路由的子级,如下所示。
// properties-routing module
const routes: Routes = [
{
path: '',
component: PropertiesComponent,
children: [
{
path: 'searchproperties',
loadChildren: () => import(`./searchproperties/searchproperties.module`).then(m => m.SearchpropertiesModule)
},
// { ...any other child routes }
]
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PropertiesRouting { }
我正在尝试在另一个路由器插座内创建一个路由器插座以用作子导航,但尝试了以下方法但它不起作用
主页组件:
<router-outlet></router-outlet>
MainRouting/AppRouting:
const routes: Routes = [
{ path: '', component: HomeComponent},
{ path: 'properties', loadChildren: () => import(`./properties/properties.module`).then(m => m.propertiesModule)}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class MainRoutingModule { }
PropertiesComponent
<button [routerLink]="[{ outlets: { properties: ['searchproperties'] } }]">Search Properties</button>
<router-outlet name="properties"></router-outlet>
PropertiesRouting:
const routes: Routes = [
{ path: '', component: PropertiesComponent},
{ path: 'searchproperties', loadChildren: () => import(`./searchproperties/searchproperties.module`).then(m => m.SearchpropertiesModule), outlet: "properties"},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PropertiesRouting { }
只需在您的属性组件中添加您的路由器插座
<!--properties.component.html-->
<button [routerLink]="[{ outlets: { properties: ['searchproperties'] } }]">
Search Properties
</button>
<router-outlet></router-outlet>
<!--no name on routerOutlet-->
然后在您的属性模块路由中,在默认路由中配置 PropertiesComponent,并将您的 SearchComponent 配置为该路由的子级,如下所示。
// properties-routing module
const routes: Routes = [
{
path: '',
component: PropertiesComponent,
children: [
{
path: 'searchproperties',
loadChildren: () => import(`./searchproperties/searchproperties.module`).then(m => m.SearchpropertiesModule)
},
// { ...any other child routes }
]
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PropertiesRouting { }