问题
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