我正在从角度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));
这是我更新的主要
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 {}
如何使用HashLocationStrategy与RC5?如何启用生产模式?
解决方法
你可以在下面使用,
路由
export const routing = RouterModule.forRoot(routes,{ useHash: true });
为了启用生产模式,在加载根NgModule之前,
import { enableProdMode } from '@angular/core'; if (<condition to enable production mode>) { enableProdMode(); }
阅读更多约LocationStrategy and browser URL styles here.
希望这可以帮助!!