0
在scalajs-react
路由器的文檔中,@ japgolly cautions users of the library that starting URLs with '/' slashes requires additional server configuration。scalajs上的漂亮網址(無'#')反應播放應用
爲了讓漂亮的URL,而不#
,到目前爲止,我試着寫一個包羅萬象的路線在播放routes
文件類似如下:
# 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))
本地運行,我有應用程序自動重定向到DashboardLoc
在localhost:9000/dashboard
和其他靜態路由在網絡應用程序中點擊它們時工作,但重新加載時失敗。