Angular懒加载路由
Angular lazy loading routing
我有如下所示的延迟加载应用程序路由:
app.routing.ts
{
path: 'reports',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},
{
path: 'report-builder',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},
我的懒加载模块路由是这样的
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }
]
},
{
path: '',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
我正在尝试实现,当用户单击报告路径时,导航到默认的 Reportscomponent,当单击 reportBuilder 路径时,导航到 ReportBuilderComponent。
如何实现。
方法一
创建两个模块,一个用于报表,一个用于报表生成器。
app.report-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }]
}
]
在report.module
中配置以上路由
app.report-builder-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
]
在报告中配置以上路由-builder.module
app.routing.js
{
path: 'reports',
loadChildren: () => import('../Reporting/report.module').then(m => m.ReportingModule)
},
{
path: 'report-builder',
loadChildren: () => import('../Reporting/report-builder.module').then(m => m.ReportBuilderModule)
}
方法二
app.report-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }
]
},
{
path: 'builder',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
app.routing.ts
{
path: 'report',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
}
希望这对你有用。
我有如下所示的延迟加载应用程序路由:
app.routing.ts
{
path: 'reports',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},
{
path: 'report-builder',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},
我的懒加载模块路由是这样的
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }
]
},
{
path: '',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
我正在尝试实现,当用户单击报告路径时,导航到默认的 Reportscomponent,当单击 reportBuilder 路径时,导航到 ReportBuilderComponent。
如何实现。
方法一
创建两个模块,一个用于报表,一个用于报表生成器。
app.report-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }]
}
]
在report.module
中配置以上路由app.report-builder-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
]
在报告中配置以上路由-builder.module
app.routing.js
{
path: 'reports',
loadChildren: () => import('../Reporting/report.module').then(m => m.ReportingModule)
},
{
path: 'report-builder',
loadChildren: () => import('../Reporting/report-builder.module').then(m => m.ReportBuilderModule)
}
方法二
app.report-routing.ts
const routes: Routes = [
{
path: '',
children: [
{ path: '', component: ReportsComponent },
{ path: ':id',component: ViewReport},
{ path: '**', component: ViewReport }
]
},
{
path: 'builder',
children: [
{ path: '', component: ReportBuilderComponent },
{ path: 'edit/:id', component: DesignReport },
{ path: '**', component: DesignReport }
]
}
app.routing.ts
{
path: 'report',
loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
}
希望这对你有用。