scalajs-react
のルータのドキュメントでは、@japgolly cautions users of the library that starting URLs with '/' slashes requires additional server configurationです。scalajs-reactで遊ぶURL(「#」なし)play app
これまでのところ、私は次のようにプレイroutes
ファイルにキャッチすべてのルートを記述しようとした、#
ずにかなりのURLを許可するには:Application.scala
# Home page
GET / com.xyz.controllers.Application.index(path: String = "")
...
# Catch-all route
GET /*path com.xyz.controllers.Application.index(path: String)
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))
ローカルでは、DashboardLoc
(localhost:9000/dashboard
)に自動リダイレクトされています。その他の静的ルートは、Webアプリでクリックすると機能しますが、読み込みに失敗します。