angular 运行时、样式和多文件在我的网络服务器上出现 404 错误

angular runtime, styles and polyfiles get a 404 error on my web server

我做了一个小 Angular 应用程序,我已经在我的计算机上构建了它,但是当我尝试打开 index.html 文件时出现 404 错误,我试图将它部署在网络服务器,但它是一样的:

GET http://www.valhatech.com/runtime-es2015.edb2fcf2778e7bf1d426.js net::ERR_ABORTED 404(未找到)

GET http://www.valhatech.com/styles.365933d9cb35ac99c497.css net::ERR_ABORTED 404(未找到)

GET http://www.valhatech.com/polyfills-es2015.2987770fde9daa1d8a2e.js net::ERR_ABORTED 404(未找到)

我的 index.html 文件是:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>McKenzieEquation</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <script src="assets/js/app.js"></script>
</head>
<body>
  <app-root></app-root>
</body>
</html>

而我的app.module.ts的内容是:

const routes: Routes = [

  { path: 'home', component: AppComponent },
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: '**', redirectTo: 'home' }
];

@NgModule({
  declarations: [
    AppComponent,
    MckenzieGraphComponent
  ],
  imports: [
    BrowserModule,FormsModule,RouterModule.forRoot(routes, { useHash: true })
  ],
  providers: [MckenzieEquationService],
  bootstrap: [AppComponent]
})
export class AppModule { }

Firefox 控制台向我发送了一个原因:CORS 请求不是 HTTP 错误或模块源的 URI 在本文档中未被授权:« file:///polyfills-es2015.2987770fde9daa1d8a2e.js »。

我发现了我的错误。在我的网络服务器上,我的 angular 页面位于以下路径: /www/mckenzieequation

我的索引文件是这样写的:

<head>
  <meta charset="utf-8">
  <title>McKenzieEquation</title>
  <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <script src="assets/js/app.js"></script>
</head>

我必须用以下代码替换基本参数:

<base href="/mckenzieequation/">

基本 href 必须指向索引文件的位置。