首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角延迟加载路由

角延迟加载路由
EN

Stack Overflow用户
提问于 2019-11-19 22:02:38
回答 1查看 111关注 0票数 0

我有如下所示的延迟加载应用程序路由:

app.routing.ts

代码语言:javascript
复制
{
  path: 'reports',
  loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},
{
  path: 'report-builder',
  loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
},

我的延迟加载模块路由如下所示

代码语言:javascript
复制
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。

如何实现这一目标。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-19 22:37:42

方法1

创建两个模块,一个用于报表,另一个用于报表生成器。

app.report-routing.ts

代码语言:javascript
复制
const routes: Routes = [
    {
       path: '',
       children: [
           { path: '', component: ReportsComponent },
           { path: ':id',component: ViewReport},
           { path: '**', component: ViewReport }]
    }
]

在report.module中配置上述路由

app.report-builder-routing.ts

代码语言:javascript
复制
const routes: Routes = [
    {
      path: '',
      children: [
        { path: '', component: ReportBuilderComponent },
        { path: 'edit/:id', component: DesignReport },
        { path: '**', component: DesignReport }
      ]
    }
]

在report-builder.module中配置上述路由

app.routing.js

代码语言:javascript
复制
{
  path: 'reports',
  loadChildren: () => import('../Reporting/report.module').then(m => m.ReportingModule)
},
{
  path: 'report-builder',
  loadChildren: () => import('../Reporting/report-builder.module').then(m => m.ReportBuilderModule)
}

方法2

app.report-routing.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
{
  path: 'report',
  loadChildren: () => import('../Reporting/reporting.module').then(m => m.ReportingModule)
}

我希望这对你有用。

参考角度:延迟加载功能模块

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58943496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档