解决方案:使用LocationStrategy方式,然后把URL后的# 替换成index.html#
app.module.ts
1 import {HashLocationStrategy,LocationStrategy} from ‘@angular/common‘; 2 3 @NgModule({ 4 imports: [ ], 5 declarations: [ 6 AppComponent, 7 ], 8 providers: [{provide: LocationStrategy,useClass: HashLocationStrategy}], 9 bootstrap: [AppComponent] 10 }) 11 export class AppModule { }
app.component.ts
1 changeURL() { 2 var text = window.location.href; 3 text.toString(); 4 var url = text.replace(/\/#/,"/index.html#"); 5 window.history.pushState({},"0",url); 6 } 7 ngAfterContentChecked(){// 每次做完组件视图和子视图的变更检测之后调用,为了防止循环替换,replace使用全替换模式 8 this.changeURL(); 9 }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。