我已经开发了 Angular 8 应用程序,我正在使用 routerLink 导航组件,这些组件可以正常工作,没有任何问题,但是当我直接在浏览器中输入相同的 URL 时,它没有显示任何内容,并且在控制台中,我看到了错误如下
比如我打开主页http://localhost:4200/home在这里添加了routerLink去http://localhost:4200/about就可以查看成功但是如果我输入URL http ://localhost:4200/about直接在 ULR 中没有显示
我已经处理了 app-routing.model.ts
const routes: Routes =
[
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{ path: '**', redirectTo: '/home', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
我有 header.component.ts 来处理导航栏,所以我在 header.component.html 中添加了
<router-outlet></router-outlet>
,然后我在 app.component.ts 中包含了 header.component.ts 的选择器,
<app-header></app-header>
然后在最后的索引中。我已经包含了 app.component.ts 的选择器,即<app-root></app-root>
你能告诉我是否有什么问题吗?
在问这个问题之前,我已经经历了下面,没有任何帮助