Angular2 rc.5和hashbang

时间:2016-08-11 17:25:50

标签: angular angular2-routing hashbang

在之前的rc.4版本中设置hashbang#!看起来像这样

bootstrap(ApplicationComponent, [....
    {provide: LocationStrategy, useClass: HashLocationStrategy},
    {provide: APP_BASE_HREF, useValue: '!'}
]);

现在在rc.5中,所有内容都发生了变化,我很难找到一种方法来获得包含#的相同地址!

Angular docs非常清楚设置路由,但在描述(https://angular.io/docs/ts/latest/guide/router.html)中有些跳过了hashbang。在rc.5 app.routing.ts

中就像这样设置散列
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });

然而不确定如何另外定义“!”在rc.5的网址中

我不确定应该如何应用以及采用何种形式。也许在boostrap中:...在app.module中的@NgModule里面,但到目前为止我没有让它工作。请建议。

1 个答案:

答案 0 :(得分:0)

你可以在app.module.ts文件中将其添加到providers数组

中,这样做
import {ReflectiveInjector} from '@angular/core';
import { Http, Response, Request, HTTP_PROVIDERS } from '@angular/http';

let injector = ReflectiveInjector.resolveAndCreate(HTTP_PROVIDERS);
let http = injector.get(Http);
let authService = new AuthService(new LocalStorage(), http);

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    routing,

  ],
  declarations: [
    AppComponent,
    MyComponent,
  ],
  bootstrap: [
    AppComponent
  ],
  providers: [
    {provide:AuthService,useValue:authService}, // over here
    AdminAuthGuard,
    UserAuthGuard
  ]
})