@NgModule({
1,hash方法:导入import { LocationStrategy, HashLocationStrategy } from '@angular/common';
配置 NgModule - providers
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
})
2,html5方法:导入import { APP_BASE_HREF, LocationStrategy, PathLocationStrategy } from '@angular/common';
配置 NgModule - providers
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
..,
providers: [
{ provide: LocationStrategy, useClass: PathLocationStrategy },
{ provide: APP_BASE_HREF, useValue: '/' }等价于<base href="/">
]
})
3,{path: '/**', redirectTo:'login'}
bootstrap(AppCmp, [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy})
]);