Helenr
更新为角2终版本在app.module.ts中:增加进口:import { HashLocationStrategy, LocationStrategy } from '@angular/common';在NgModule Provider中添加:{provide: LocationStrategy, useClass: HashLocationStrategy}例(附件.module.ts):import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
bootstrap: [AppComponent],
})
export class AppModule {}替代使用RouterModule.forroot和{useHash:true}参数。例子:(来自角文档)import { NgModule } from '@angular/core';
...
const routes: Routes = [//routes in here];
@NgModule({
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot(routes, { useHash: true })
],
bootstrap: [AppComponent]
})
export class AppModule { }