修改Angular路由模式

SPA应用一般有两种:html5 history模式( http://localhost:4200/user),看起来更加美观,然而如没有后台支持,刷新页面就会报:Cannot GET /pagurl之类的错,一种是Hash模式( http://localhost:4200/#/user)。

权衡之后,决定将模式改为Hash模式:

  1. 引入所需的包:
  2. import {HashLocationStrategy, LocationStrategy} from '@angular/common';
  3. 放到App-module里的providers里
  4. providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
  5. npm start运行即可

猜你喜欢

转载自blog.csdn.net/qq_40882724/article/details/81536219