Ionic4/Angular 项目Web打包之后,部署到服务器,刷新访问404解决方法

Ionic4/Angular 项目Web打包之后,部署到服务器,刷新访问404解决方法


项目使用Ionic4/Angular8开发,使用的是Angular路由,通过

ionic build --prod

进行编译,然后把www目录下的内容发布到IIS中,在浏览器中进行访问(http://domain/index.html自动跳转到http://domain/tabs/func),这时点击浏览器的顶部的刷新按钮就出现404的问题,解决办法是使用哈希路由,让访问地址变为http://domain/#/tabs/func,具体实现就是修改app.module.ts
1、首先在开头位置增加以下代码:

import { LocationStrategy, HashLocationStrategy } from '@angular/common';

2、修改@NgModule的代码,增加以下内容:

@NgModule({
  providers: [
    { provide: LocationStrategy, useClass: HashLocationStrategy }
  ]
})
发布了138 篇原创文章 · 获赞 303 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/zlbdmm/article/details/104993084