我已经在 Angular 2 中创建了演示应用程序,当我在本地运行它时它工作正常但当我在 iis serve 上发布它时出现错误。
我收到这个错误
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 { }
我是否遗漏了什么或需要任何额外的内容才能发布?
最佳答案
发现是版本冲突
让我们玩吧:D
npm uninstall -g @angular/cli
npm cache clean
然后在那之后
npm install -g @angular/cli@latest --save
在新文件夹中创建新项目
ng 新项目名称
关闭编辑器
将旧项目的src复制到新项目
运行编辑器
构建和部署
ng build --prod --aot --no-sourcemap --base-href
关于在 iis 上发布时出现 Angular 2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46704470/