本文介绍了如何在Angular 2 RC5中使用HashLocationStrategy进行引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Angular 2 RC4升级到RC5

I'm upgrading from Angular 2 RC4 to RC5

这是我当前的main.ts

Here's my current 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));

这是我更新的main.ts

Here's my updated main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

这是app.modules.ts

Here's the 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?如何启用生产模式?

How can I use HashLocationStrategy with RC5? How can I enable Production mode?

推荐答案

您可以在下面使用

路由

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

用于启用生产模式,然后加载根NgModule

for enabling production mode, before loading root NgModule,

import { enableProdMode } from '@angular/core';

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

在此处详细了解 LocationStrategy和浏览器URL样式.

希望这会有所帮助!

这篇关于如何在Angular 2 RC5中使用HashLocationStrategy进行引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 08:50