2016-04-21 4 views
5

を行うとき、私は、このソースコードを見ていた私のために動作しません:https://github.com/angular/angular.io/blob/master/public/docs/_examples/toh-5/dart/lib/app_component.dartルーティングがハードリフレッシュ

と私はルートに行くとき、それは今の私のアプリケーションの意志ルートと思われます。

はlocalhost:8080/

ルーティングアップデートを私は自分のアプリケーションを移動、私が何かをしていた場合と思われるよう:localhost:8080/dashboard basecaseで、ハードリフレッシュを行い、それが失敗しました。それは私に404 not found!エラーを与えるでしょう。

もし私がすれば、それはちょうど見つけることができます:localhost:8080/#!/dashboardそれは私のアプリケーションに渡されたアドレスではありません。私が持っているのindex.htmlで

次のよう<base href="/">

マイApp_Component.dartファイルは次のとおりです。

import 'package:angular2/angular2.dart'; 
import 'package:angular2/router.dart'; 

import 'hero_component.dart'; 
import 'heroes_component.dart'; 
import 'dashboard_component.dart'; 
import 'hero_service.dart'; 
@Component(
    selector: "my-app", 
    directives: const [ROUTER_DIRECTIVES], 
    providers: const [HeroService, ROUTER_PROVIDERS], 
    templateUrl: "app_component.html") 
@RouteConfig(const [ 
    const Route(
     path: "/dashboard", 
     name: "Dashboard", 
     component: DashboardComponent, 
     useAsDefault: true), 
    const Route(
     path: "/detail/:id", name: "HeroDetail", component: HeroDetailComponent), 
    const Route(path: "/heroes", name: "Heroes", component: HeroesComponent) 
]) 
class AppComponent { 
    String title = "Tour of Heroes"; 
} 

私がこれを除いてすべてのために働いてルーティングしているようです。

localhost:8080/detail/14としていますが、これで正しいコンポーネントが開かれます。これは、アプリケーション全体をナビゲートするときと同じくらい新しいサイト参照で今行われていないことです。

答えて

3

あなたがpub servePathLocationStrategyを使用することができますhttps://pub.dartlang.org/packages/pub_serve_rewrites -wrapperこのpub serveを使用することができますPathLocationStrategy使用したい場合は

bootstrap(AppComponent, [ 
    HeroService, 
    ROUTER_PROVIDERS, 
    provide(LocationStrategy, useClass: HashLocationStrategy) 
]) 

HashLocationStrategy変化にプロバイダを切り替えるには。

展開するには、HTML5 pushStateをサポートするためにそこに使用するWebサーバーを設定する必要があります。

+1

完璧!よく働く。私は研究しており、ここにそれが気付いています:https://github.com/ng2-dart-samples/router/blob/master/web/main.dart。私はこの答えが一番好きです。 – Fallenreaper

+0

pub_serve_rewritesの代わりに、たとえばnginxをプロキシとしてプロキシとして使用することもできます。うん、カスパーはAngular2ダートのコミュニティでかなり活発だった。彼は現在、彼の数学の研究で忙しいと思われる: - / –

1

ルートはアプリ内にのみ存在し、サーバは何も知らず、存在しないデフォルトページ/ファイルの場合は/dashboardまたは/detail/14のパスをチェックするだけです。

あなたのすべてのアプリルートについて、アプリケーションのindex.html(ここではあなたのhtml名)に移動するようにサーバールータを設定する必要があります。

0

localhost:8080/dashboardが失敗した場合は、PathLocationStrategyではなくHashLocationStrategyを使用していることがわかります。

bootstrap()機能を確認するか、HashLocationStrategyが注入されていないことを確認してください。

関連する問題