app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers:
[BureauApiService,BureauStateWorkflowComponent,CommondataApiService]
})
export class AppComponent implements OnInit {
constructor(
private router: Router,
private bureau:BureauStateWorkflowComponent,
private _location: Location,
) { }
ngOnInit(){
//this.bureau.getPosts();
this.router.navigate(['/']);
localStorage.clear();
}
}
在localhost中,当浏览器刷新时,此路由器导航功能正常。导航到主页 但在iis中部署之后就无法正常工作了。 返回此类错误页面。 HTTP错误404.0 - 未找到 您要查找的资源已被删除,名称已更改或暂时不可用。
答案 0 :(得分:0)
最后我找到了答案。我使用了LocationStrategy和HashLocationStrategy到app.module.ts类的provider部分,并将app.component.ts类更改为如下所示
在app.module.ts
import { HashLocationStrategy,LocationStrategy } from '@angular/common';
@NgModule({
providers: [Configurations, BureauApiService, CreditorApiService,{provide:
LocationStrategy, useClass: HashLocationStrategy},FlashMessagesModule],
})
export class AppModule { }
在app.component.ts
ngOnInit(){
//this.bureau.getPosts();
this.router.navigate(['/#']);
localStorage.clear();
}
它正常运作