1

のルーターのドキュメントでscalajs-react、@japgolyはライブラリのユーザーに、「/」スラッシュで始まる URL には追加のサーバー構成が必要であると警告しています

のないきれいな URL を許可する#ために、これまでのところroutes、次のように Play ファイルにキャッチオール ルートを記述しようとしました。

# Home page
GET     /          com.xyz.controllers.Application.index(path: String = "")

...
# Catch-all route
GET     /*path     com.xyz.controllers.Application.index(path: String)

一致するインデックス パスでApplication.scala

def index(path: String = "") = Action {
  Ok(views.html.index("Title"))
}

RouterConfigDsl最後に、フロントエンドで使用して宣言されたルート:

def create = Router(BaseUrl.until_#, RouterConfigDsl[Loc].buildConfig { dsl =>
    import dsl._

    ( emptyRule
    | staticRoute(root, DashboardLoc)                   ~> render(filler("Dashboard"))
    | staticRoute("purchase-orders", PurchaseOrdersLoc) ~> render(filler("Purchase Orders"))
    | staticRoute("dashboard", DashboardLoc)            ~> render(filler("Dashboard"))
    | staticRoute("items", ItemsLoc)                    ~> render(ItemGallery())
    | staticRoute("customers", CustomersLoc)            ~> render(filler("Customers"))
    | staticRoute("sales-orders", SalesOrdersLoc)       ~> render(filler("Sales Orders"))
    | staticRoute("preorders", PreordersLoc)            ~> render(filler("Pre-orders"))
    ).notFound(redirectToPage(DashboardLoc)(Redirect.Replace))
     .setTitle(l => s"XYZ | ${l.name}")
}.renderWith(layout))

ローカルで実行すると、アプリが at に自動リダイレクトさDashboardLoclocalhost:9000/dashboard、他の静的ルートは Web アプリ内でクリックすると機能しますが、リロードすると失敗します。

4

1 に答える 1

1

結局のところ、問題は のBaseUrl.until#代わりにを使用していたことにありBaseUrl.fromWindowOrigin_/ました。これで、すべてのルートが期待どおりに機能します。

于 2016-12-28T14:19:49.360 に答える