在scalajs-react路由器的文档中,@japgolly 警告库的用户使用'/‘斜杠启动URL需要额外的服务器配置。
为了允许没有#的漂亮URL,到目前为止,我已经尝试在Play routes文件中编写一个catch路由,如下所示:
# 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 at localhost:9000/dashboard,其他静态路由在web应用程序中单击它们时工作,但在重新加载时失败。
发布于 2016-12-28 14:19:49
事实证明,问题毕竟是使用BaseUrl.until#而不是BaseUrl.fromWindowOrigin_/。现在所有的路线都像预期的那样工作。
https://stackoverflow.com/questions/41361493
复制相似问题