我製作了一個使用Angular 2的網站。我已經在生產中的一臺linux服務器上部署了該網站。當我單擊導航上的鏈接時,路線似乎工作正常,但當頁面刷新時顯示404錯誤。一切似乎在本地主機上正常工作,但不在現場服務器上。我甚至嘗試使用HashLocationStrategy但無濟於事。Angular 2網站頁面刷新在localhost上工作,但在活動服務器上刷新顯示404錯誤
app.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { RulesComponent } from './rules/rules.component';
import { DownloadsComponent } from './downloads/downloads.component';
import { RegisterComponent } from './register/register.component';
import { ContactComponent } from './contact/contact.component';
const appRoutes: Routes = [
{path: '', component: HomeComponent},
{path: 'about', component: AboutComponent},
{path: 'rules', component: RulesComponent},
{path: 'downloads', component: DownloadsComponent},
{path: 'register', component: RegisterComponent},
{path: 'contact', component: ContactComponent}
];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
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 { AppComponent } from './app.component';
import { routing, appRoutingProviders } from './app.routing';
import { HeaderComponent } from './header.component';
import { FooterComponent } from './footer.component';
import { NavComponent } from './nav.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { RulesComponent } from './rules/rules.component';
import { DownloadsComponent } from './downloads/downloads.component';
import { RegisterComponent } from './register/register.component';
import { ContactComponent } from './contact/contact.component';
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent,
NavComponent,
HomeComponent,
AboutComponent,
RulesComponent,
DownloadsComponent,
RegisterComponent,
ContactComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
providers: [ {provide: LocationStrategy, useClass: HashLocationStrategy} ],
bootstrap: [AppComponent]
})
export class AppModule { }
我的基本href是 「/」。有什麼我做錯了嗎?提前致謝。