我正在从角2 RC4升级到RC5
这是我现在的主播。

import {enableProdMode} from '@angular/core';
import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app/app.component';
import {AppRoutes} from './app/app.routes';
import { provideRouter } from '@angular/router';
import { XHRBackend } from '@angular/http';
import { HTTP_PROVIDERS } from '@angular/http';
import { LocationStrategy,
         HashLocationStrategy } from '@angular/common';
import {disableDeprecatedForms, provideForms} from '@angular/forms';
import {provide} from '@angular/core';

enableProdMode();
bootstrap(AppComponent, [
  disableDeprecatedForms(),
  provideForms(),
  provideRouter(AppRoutes)
  ,HTTP_PROVIDERS,
  provide(LocationStrategy, {useClass: HashLocationStrategy})

])
  .catch(err => console.error(err));

这是我最新的main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

这是app.modules.ts
import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import {HTTP_PROVIDERS} from '@angular/http';
import { AppComponent }  from './app.component';
import { routing } from './app.routes';

@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        routing
    ],
    declarations: [
        AppComponent
    ],
    bootstrap: [ AppComponent]
})
export class AppModule {}

如何在RC5中使用hashLocationStrategy?如何启用生产模式?

最佳答案

你可以在下面使用,
路由

 export const routing = RouterModule.forRoot(routes, { useHash: true });

对于启用生产模式,在加载rootNgModule之前,
import { enableProdMode } from '@angular/core';

if (<condition to enable production mode>) {
   enableProdMode();
}

阅读有关LocationStrategy and browser URL styles here的更多信息。
希望这有帮助!!

09-11 19:44