剛遇到Angular4項目npm run build 後部署到服務器能夠訪問,可是刷新頁面會出現404的錯誤!轉載一大神的操做npm
解決angular2頁面刷新後報404錯誤辦法:
配置app.module.ts
import {HashLocationStrategy , LocationStrategy} from '@angular/common';
@NgModule({
declarations: [AppCmp],
bootstrap: [AppCmp],
imports: [BrowserModule, routes],
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]
});
主要添加的代碼:
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]
這樣設置後,訪問angular站點,會自動在根節點後面加一個#錨點。再次刷新便不會報404錯誤了。
原文: http://blog.csdn.net/qq_38321709/article/details/75045384bootstrap