typescript 如何在 Angular 2 RC5 中使用 HashLocationStrategy 进行引导
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38964450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to bootstrap with HashLocationStrategy in Angular 2 RC5
提问by user6123723
I'm upgrading from Angular 2 RC4 to RC5
我正在从 Angular 2 RC4 升级到 RC5
Here's my current main.ts
这是我目前的 main.ts
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));
Here's my updated main.ts
这是我更新的 main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
Here's the app.modules.ts
这是 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 {}
How can I use HashLocationStrategy with RC5? How can I enable Production mode?
如何在 RC5 中使用 HashLocationStrategy?如何启用生产模式?
回答by Madhu Ranjan
You may use below,
您可以在下面使用,
routing
路由
export const routing = RouterModule.forRoot(routes, { useHash: true });
for enabling production mode, before loading root NgModule
,
为了启用生产模式,在加载 root 之前NgModule
,
import { enableProdMode } from '@angular/core';
if (<condition to enable production mode>) {
enableProdMode();
}
Read more about LocationStrategy and browser URL styles here.
在此处阅读有关LocationStrategy 和浏览器 URL 样式的更多信息。
Hope this helps!!
希望这可以帮助!!