gpt4 book ai didi

angular - 如何在 Angular 2 RC5 中使用 HashLocationStrategy 进行引导

转载 作者:太空狗 更新时间:2023-10-29 16:54:19 45 4
gpt4 key购买 nike

我正在从 Angular 2 RC4 升级到 RC5

这是我当前的 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

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 的信息.

关于angular - 如何在 Angular 2 RC5 中使用 HashLocationStrategy 进行引导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38964450/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com