After the angular4.0 project executes npm run build, the entry page is displayed normally.
But when the page is refreshed, an error 404 is reported and the page is not found.
The reason for this problem should be that the routing address could not be found, and then the following solution was found.
Find the app.module.ts file, this is the root module. Add HashLocationStrategy and LocationStrategy services to the module.
// 1. Introduce HashLocationStrategy and LocationStrategy services import {HashLocationStrategy, LocationStrategy} from '@angular/common'; // 2. Inject the service @NgModule ({ declarations: [ ], imports: [ ], providers: [ {provide: LocationStrategy, useClass: HashLocationStrategy} ], bootstrap: [AppComponent] })