首页 > 解决方案 > 导航到 /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 }
];

标签: javascriptangular

解决方案


只需将您的代码更新为

[{
    path: '',
    pathMatch: 'full',
    redirectTo: 'home' // you dont need /home
  },
  {
    path: 'home',
    component: IndexComponent
  }
]

推荐阅读