欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

angular6页面刷新时报HTTP Status 404 – Not Found

程序员文章站 2022-05-31 21:37:58
...

错误信息:

HTTP Status 404 – Not Found
Type Status Report

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.40

angular6页面刷新时报HTTP Status 404 – Not Found

解决方法----开启 Hash 模式

在app.module.ts中

1.导入 HashLocationStrategy 及 HashLocationStrategy
import { HashLocationStrategy,LocationStrategy } from "@angular/common";
2.配置 NgModule - providers
@NgModule({
  imports: [
    BrowserModule,
    RouterModule.forRoot(routes)
  ],
  ...,
  providers: [
    { provide: LocationStrategy, useClass: HashLocationStrategy }
  ]
})