のルーターのドキュメントで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 に自動リダイレクトさDashboardLoc
れlocalhost:9000/dashboard
、他の静的ルートは Web アプリ内でクリックすると機能しますが、リロードすると失敗します。