玩!,如何使用" _escaped_fragment _"创建路线参数?

时间:2016-05-30 16:21:08

标签: scala playframework routing

我正在使用Play! scala 2.4和我尝试使用" _escaped_fragment _"创建一条路线。参数,但我无法在routes.conf文件中执行此操作。 事实上,

GET /  @application.Application.indexOrSnapshot(_escaped_fragment_: Option[String])

返回编译错误。

所以,我尝试添加一个像这样的sird路径(如文档中所述):

class SirdComponents(context: Context) extends BuiltInComponentsFromContext(context) {
  lazy val router = Router.from {
    case GET(p"/?_escaped_fragment_=$path") => Action {
      Results.Ok(s"Hello $path")
    }
  }
}

但我不明白我该如何使用它,特别是在哪里可以放置这段代码。

这样做的最佳方式是什么?

1 个答案:

答案 0 :(得分:2)

在这种情况下,路径解析器比scala解析器更严格一些。 在反引号中包装参数应该有效:

GET /  @application.Application.indexOrSnapshot(`_escaped_fragment_`: Option[String])