我已经在Angular 2中创建了演示应用程序,在本地运行时它可以正常工作,但是在发布到IIS服务器上时出现错误。
我遇到的错误是:
Failed to load resource: the server responded with a status of 404 (Not Found)
这里是我的代码
index.html
。请查看
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MyApp</title>
<base href="/">
<link rel="stylesheet" href="https://bootswatch.com/darkly/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
app.router.ts
import {ModuleWithProviders} from '@angular/core';
import {Routes,RouterModule} from '@angular/router';
//import {AppComponent} from './app.component'
import {AboutComponent} from './about/about.component'
import {TechnologyComponent} from './technology/technology.component'
export const router : Routes = [
{path:'',redirectTo:'about',pathMatch:'full'},
{path:'about',component:AboutComponent},
{path:'tachnology',component:TechnologyComponent}
]
export const routes: ModuleWithProviders = RouterModule.forRoot(router)
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
//import { HashLocationStrategy, LocationStrategy } from '@angular/common'
import {routes} from './app.router'
import { AppComponent } from './app.component';
import { AboutComponent } from './about/about.component';
import { TechnologyComponent } from './technology/technology.component';
import {AboutSrvice} from './about/about.service'
@NgModule({
declarations: [
AppComponent,
AboutComponent,
TechnologyComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routes
],
//There is two ways you can use service first here you can add service in provider or either you can add it in about.component.ts file in @Component({}) section
// providers: [AboutSrvice,{provide: LocationStrategy, useClass: HashLocationStrategy}],
providers: [AboutSrvice],
bootstrap: [AppComponent]
})
export class AppModule { }
我是否漏掉了什么或需要额外的内容来发布?
ng build
和ng build --prod
的命令来构建项目,并从 dist 文件夹中获取文件。 - Bharatng build --prod --aot --no-sourcemap
。 - Tarek.Eladly