javascript - Angular 9:延迟加载组件内的子路由不起作用
问题描述
我有应用程序组件,我在其中延迟加载带有组件 profilecomponent 的 create-new-module。现在在配置文件组件中,我点击 router.navigate 并尝试加载另一个子项详细信息来代替配置文件,但它不起作用,控制台中也没有错误。
请帮忙
// App component route
const routes: Routes = [
{
path: 'create-new-emp',
loadChildren: () => import('./create-new-emp/create-new-emp.module').then(c => c.CreateNewEmpModule),
},
{ path: '', redirectTo: 'create-new-emp', pathMatch: 'full'},
{ path: '**', redirectTo: 'create-new-emp'}
];
// Emp Module Route
const routes: Routes = [
{ path: '', component: ContainerComponent,
children: [
{ path: '', component: ProfileComponent, outlet: 'form'},
{ path: 'profile', component: ProfileComponent, outlet: 'form'},
{ path: 'detail', component: DetailComponent, outlet: 'form' }] }
];
// Trying to hit below link but not working
this.router.navigate(['detail'])
<app-component>
<router-outlet>
<container-component>
<profile-component></profile-component>
</container-component>
</router-outlet>
</app-component>
解决方案
复杂的只有这些信息来帮助。但是角度导航数量组件/页面的方式。我认为您要做的是在组件之间导航(根据您的 router.ts)。如果你想导航,你只需要在你的 html 代码中使用 router-outlet 而不是在 HTML 代码中使用组件标签。
改变这个:
<app-component>
<router-outlet>
<container-component>
<profile-component></profile-component>
</container-component>
</router-outlet>
</app-component>
对此:
<app-component>
<router-outlet>
</router-outlet>
</app-component>
然后,进入 ContainerComponent.html,您需要重复导航到配置文件的详细信息,因为这些是子路由。
<router-outlet></router-outlet>
这将为您提供有关所需内容的更多信息。
推荐阅读
- javascript - 在 XAMPP 中部署 React
- r - R日期格式在sapply后更改
- laravel - 请求get方法路由处理
- php - 当上传的文件名已存在于数据库中时,在处理 PHP 表单时显示警报
- android - 如何解决:应用程序安装被播放保护问题阻止
- vue.js - NPM 脚本“serve”退出,但没有表明服务器正在侦听请求:“npm”不是内部或外部命令
- git - 如何查看 Gerrit 中标签的创建者
- excel - PowerShell Excel 插入公式不起作用
- google-apps-script - 有没有办法通过 Appscript 或在工作表上按用户数量列出 Google Workspace 应用程序的使用情况
- javascript - MaterializeCSS onAutocomplete 不触发 javascript 回调函数