Run*_*lse 6 routing playframework-2.0 angularjs
我正在使用播放框架为我的休息服务开发一个角度应用程序.公用文件夹中的所有内容都是一个有角度的应用程序(样式表,javascripts,图像和HTML).我希望每个请求都不会被样式表,javascripts,模板或图像文件夹中的某些内容路由到index.html页面.这样,角度路由可以从那里接管......
作为旁注,我可以提一下,我将把每个restservice放在/services/
哪个链接到我自己的java控制器.
在游戏框架2.3.4中是否可以定义一条捕获所有路径而不必使用匹配元素的路由?
这是我到目前为止的路线:
GET / controllers.Assets.at(path="/public", file="index.html")
GET /stylesheets/*file controllers.Assets.at(path="/public/stylesheets", file)
GET /javascripts/*file controllers.Assets.at(path="/public/javascripts", file)
GET /templates/*file controllers.Assets.at(path="/public/templates", file)
GET /images/*file controllers.Assets.at(path="/public/images", file)
#this line fails
GET /* controllers.Assets.at(path="/public", file="index.html")
Run Code Online (Sandbox Code Playgroud)
不可能省略匹配元素的使用,但是您可以通过控制器路由客户端。路由定义如下所示:
GET /*path controllers.Application.matchAll(path)
Run Code Online (Sandbox Code Playgroud)
相应的控制器可以实现如下:
public class Application extends Controller {
public static Result matchAll(String path) {
return redirect(controllers.routes.Assets.at("index.html"));
}
}
Run Code Online (Sandbox Code Playgroud)
更新资料
如果您不想重定向客户端,则可以将静态资源作为流返回。在这种情况下,需要一个响应MIME类型。
public class Application extends Controller {
public static Result matchAll(String path) {
return ok(Application.class.getResourceAsStream("/public/index.html")).as("text/html");
}
}
Run Code Online (Sandbox Code Playgroud)