angular-cli里默认使用的是HTML5 History 模式,url类似 http://localhost:4200/task-list,URL看着比较舒服,比较美观。在路由页面刷新就会404
还有一种模式是hash模式,url类似 http://localhost:4200/#/task-list,跳转到路由页面再刷新还是会停留在当前路由。
开启方法
app.module.ts中引入并provider
[plain]import {HashLocationStrategy, LocationStrategy} from ‘@angular/common’;
…
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
..
[/plain]
就可以了
Web前端(W3Cways.com) - Web前端学习之路
评论前必须登录!
注册