scalajs上的漂亮网址(没有'#') - 反应Play应用

时间:2016-12-28 11:48:45

标签: scala.js playframework-2.5 scalajs-react

echo "AS_ADMIN_PASSWORD=" > /tmp/glassfishpwd && \ echo "AS_ADMIN_NEWPASSWORD=$GLASSFISH_ADMIN_PASSWORD" >> /tmp/glassfishpwd && \ asadmin --user=admin --passwordfile=/tmp/glassfishpwd change-admin-password --domain_name domain1 && \ asadmin start-domain && \ echo "AS_ADMIN_PASSWORD=$GLASSFISH_ADMIN_PASSWORD" > /tmp/glassfishpwd && \ asadmin --user=admin --passwordfile=/tmp/glassfishpwd enable-secure-admin && \ /glassfish-4.1/bin/asadmin --user=admin stop-domain && \ rm /tmp/glassfishpwd 路由器的文档中,@ japgolly cautions users of the library that starting URLs with '/' slashes requires additional server configuration

要允许不含scalajs-react的漂亮网址,到目前为止,我已尝试在Play #文件中编写一个包含所有内容的路径,如下所示:

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,其他静态路由在Web应用程序中单击它们时工作但在重新加载时失败。

1 个答案:

答案 0 :(得分:1)

事实证明,问题毕竟是使用BaseUrl.until#而不是BaseUrl.fromWindowOrigin_/。现在所有路线都按预期工作。