首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >漂亮的URL(没有'#')在金刚-反应播放应用程序

漂亮的URL(没有'#')在金刚-反应播放应用程序
EN

Stack Overflow用户
提问于 2016-12-28 11:48:44
回答 1查看 128关注 0票数 1

scalajs-react路由器的文档中,@japgolly 警告库的用户使用'/‘斜杠启动URL需要额外的服务器配置

为了允许没有#的漂亮URL,到目前为止,我已经尝试在Play routes文件中编写一个catch路由,如下所示:

代码语言:javascript
复制
# Home page
GET     /          com.xyz.controllers.Application.index(path: String = "")

...
# Catch-all route
GET     /*path     com.xyz.controllers.Application.index(path: String)

使用Application.scala中的匹配索引路径

代码语言:javascript
复制
def index(path: String = "") = Action {
  Ok(views.html.index("Title"))
}

最后,在前端使用RouterConfigDsl声明的路由:

代码语言:javascript
复制
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应用程序中单击它们时工作,但在重新加载时失败。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-28 14:19:49

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41361493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档