modern-web-template
modern-web-template copied to clipboard
Routing AngularJS Versus PlayFramework Paths
AngularJS routes are not properly handled by the backend. For example:
/users/create
Results in an unresolved request in the backend. It would be preferred if in this case the back end forwards the URI to AngularJS, so that the template can be resolved in the front end. For example, consider the proposed route:
GET /*any @controllers.Application.main(any)
And the following controller function:
def main(any: String) = Action {
logger.info("Serving index page via AngularJS...")
val javascripts = { ... }
Ok(views.html.index(javascripts))
}
Using this approach, PlayFramework will forward the URI to AngularJS. The drawback in this case is that PlayFramework routes must be different from AngularJS ones to avoid conflicts. This can be solved by adding a prefix to all the asynchronous routes (e.g. /api/users instead of /users). I am not 100% sure this is the best way to solve the problem, so it would be nice to hear more ideas.