@NgModule({

imports: [
BrowserModule,
ElModule.forRoot(),
HttpModule,
// RouterModule.forRoot(ROUTES)
RouterModule.forRoot(
ROUTES,
{
enableTracing: false,
useHash: true
}
)
],


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})
]);

posted on 2018-03-01 18:20  happiness木木  阅读(233)  评论(0编辑  收藏  举报