After the angular4.0 project is built and released, an error 404 is reported when refreshing the page

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]
})

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341474&siteId=291194637