[英]angular runtime, styles and polyfiles get a 404 error on my web server
我做了一個小 Angular 應用程序,我已經在我的計算機上構建了它,但是當我嘗試打開 index.html 文件時出現 404 錯誤,我嘗試將它部署在 Web 服務器上,但它是相同的:
獲取http://www.valhatech.com/runtime-es2015.edb2fcf2778e7bf1d426.js net::ERR_ABORTED 404(未找到)
獲取http://www.valhatech.com/styles.365933d9cb35ac99c497.css net::ERR_ABORTED 404(未找到)
獲取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 »。
我發現了我的錯誤。 在我的 Web 服務器上,我的 Angular 頁面位於以下路徑:/www/mckenzieeqation
我的索引文件是這樣寫的:
<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/">
base href 必須指向索引文件的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.