Is there a way to use Play routing in scala js files?

天涯浪子 提交于 2019-12-12 16:32:41

问题


I use Play! Scala 2.4 with scala js, and I would like to know if there is a way to get the routing config file from the scala js files.

It would be very convenient since it would allow me to replace urls as string by something like application.routes.Application.admin().

Do you know any workaround to do this?


回答1:


You can use javascript reverse routing. It will help you to define routes from your js code. It will look like this:

@helper.javascriptRouter("jsRoutes")(
  routes.javascript.Application.admin
)
...
<script>
   console.log(jsRoutes.routes.Application.admin())
</script>



回答2:


Supporting the previous answer, you can take a look at my code for a rather complex real-world example.

The JavaScript side

The Scala.js facade around that



来源:https://stackoverflow.com/questions/36135204/is-there-a-way-to-use-play-routing-in-scala-js-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!