javascript - 导航到 /home 或新页面时看不到 html 页面。仅显示索引
问题描述
在这个项目中,我正在尝试学习 Angular 和嵌套组件。由于某种原因,我无法导航到 /home 页面。页面未显示。请提供任何帮助。谢谢你。
应用程序路由.module.ts
const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: '/home' },
{ path: 'home', component: IndexComponent },
{ path: 'view/:id', component: ShowComponent },
{ path: 'new', component: NewComponent },
{ path: 'edit/:id', component: EditComponent },
{ path: '**', component: IndexComponent }
];
解决方案
只需将您的代码更新为
[{
path: '',
pathMatch: 'full',
redirectTo: 'home' // you dont need /home
},
{
path: 'home',
component: IndexComponent
}
]
推荐阅读
- python - 熊猫数据框,每个步骤的重复行值
- asp.net-core - 单元测试以确保将所有必需的服务添加到 .Net Core DI 容器中
- python - 无法使用 pytest 模拟 for 循环中存在的内容
- java - 为什么 String 方法 regionMatches 不委托给重载方法
- javascript - 未捕获的类型错误:无法仅在在线网站中读取 null 的属性“值”
- php - 网址变成双倍
- python - 如何在 Python 中使用 LDA 构建数据框
- amazon-web-services - 没有 AWS 访问密钥和秘密 AWS 服务不工作(IAM 角色关联)
- javascript - 如何在 JQUERY 数据表中添加下拉菜单?
- java - How to avoid duplicating a function call in this JPA/JPQL query?