angular4.0项目build发布后,刷新页面报错404

时间:2017-10-24 14:44:10   收藏:0   阅读:450

angular4.0项目执行npm run build后,进入页面正常显示。

但是当刷新页面时,报错404,页面未找到。

出现这个问题的原因,应该是找不到路由地址导致的,然后找到了下面的解决方案。

找到app.module.ts文件,这个是根模块。在模块中加入HashLocationStrategyLocationStrategy服务。

// 1、引入HashLocationStrategy、LocationStrategy服务
import {HashLocationStrategy, LocationStrategy} from @angular/common;

// 2、注入服务
@NgModule({
  declarations: [
    
  ],
  imports: [
    
  ],
  providers: [
    {provide: LocationStrategy, useClass: HashLocationStrategy}
  ],
  bootstrap: [AppComponent]
})

ok,就是酱紫,完美解决。

 

 

原文:http://www.cnblogs.com/minigrasshopper/p/7723304.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!