2016-09-20 14 views
1

最近Angular2の最終リリースにアップグレードしました。私はHashLocationStrategyがAngular2 Final/RC7のアップデートの後に私のために働かなくなったので、これが重複しているとは思わない。以前は、ページをリフレッシュすると、関連するルートをハッシュ(#)でフェッチ/取得し、ページをリロードしていました。今、私は、任意のリフレッシュページでこのエラーを取得:Angular2 Final:Page Refreshエラー、「Can not GET」ルート。 HashLocationStrategy failed

enter image description here

http://localhost:3000/main/home代わりのhttp://localhost:3000/#/main/homeをロードしようとしているので、私はこれが起こっていると考えています。

なぜHashLocationStrategyが機能しなくなったのですか? @NgModuleHashLocationStrategyをインポートする必要がありますか?

+0

可能な重複がhttp://stackoverflow.com/questions/38265536/angular-2-rc-4-hashlocationstrategy-no-longer-working – Supamiu

+1

https://angular.io/docs/ts/latest/guide/router.html#!# - ハッシュロケーションストラテジー - ここに必要なのはすべてです。 – Supamiu

答えて

3

あなたAppModuleのプロバイダにHashLocationStrategyからLocationStrategyを設定する必要があります。

import { LocationStrategy, HashLocationStrategy } from '@angular/common'; 

@NgModule({ 
    imports: [ 
     ... 
    ], 
    declarations: [ 
     ... 
    ], 
    bootstrap: [...], 
    providers: [ 
     { provide: LocationStrategy, useClass: HashLocationStrategy } 
    ] 
}) 

export class AppModule { } 
+1

恐ろしいことに、これは私が逃したものです – jhhoff02

0

それはまだ有効ですが、きれいな方法があれば私にはわからない:の

import {RouterModule} from '@angular/router'; 

@NgModule({ 
    imports: [ 
     RouterModule.forRoot(ROUTES_ARRAY, {useHash: true}) 
    ], 
    declarations: [ 
     ... 
    ], 
    bootstrap: [...], 

}) 

export class AppModule { } 
関連する問題