Ron*_*Ron 5 routelink angular-routing angular angular-routerlink
我开发了 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]
})
Run Code Online (Sandbox Code Playgroud)
我有 header.component.ts 来处理导航栏,所以我
<router-outlet></router-outlet>
在 header.component.html 中添加了<app-header></app-header>
,然后在app.component.ts 中包含了 header.component.ts 的选择器,然后在最后的index.js 中包含了 header.component.ts 的选择器
。 html 我已经包含了 app.component.ts 的选择器,即<app-root></app-root>
你能告诉我是否有问题。
在问这个问题之前,我已经经历了下面的一切,没有任何帮助
小智 7
在服务器上,我们可以使用 hashStrategy 进行路由。
在路由文件中只需替换RouterModule.forRoot(routes)
为 RouterModule.forRoot(routes,{useHash : true})
.
归档时间: |
|
查看次数: |
3004 次 |
最近记录: |