在 iis 上发布时出现 Angular 2 错误

Bha*_*rat 5 iis angular

我已经在 angular 2 中创建了演示应用程序,当我在本地运行它时它工作正常,但是当我在 iis serve 上发布它时出现错误。

我得到这个错误

Failed to load resource: the server responded with a status of 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

这是我的代码 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>
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

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 { }
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了什么或需要任何额外的内容来发布?。

小智 1

结果发现这是版本冲突,所以

让我们一起玩吧:D

npm uninstall -g @angular/cli
npm cache clean
Run Code Online (Sandbox Code Playgroud)

然后在那之后

npm install -g @angular/cli@latest --save
Run Code Online (Sandbox Code Playgroud)

在新文件夹中创建新项目

ng new 项目名称

关闭编辑器

将旧项目的src复制到新项目

运行编辑器

构建和部署

ng build --prod --aot --no-sourcemap --base-href
Run Code Online (Sandbox Code Playgroud)