在之前的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里面,但到目前为止我没有让它工作。请建议。
答案 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
]
})