我正在尝试找出一种方法来呈现或路由到 Play 公共(public)文件夹中托管的一些静态 Web 应用程序。我的元素结构如下:
myapp
+ app
+ conf
+ modules
+ public
| + webapp1
| + css
| + images
| + index.html
| + webapp2
| + css
| + images
| + index.html
+ ...
我想渲染 webapp1 和 webapp2。每个网络应用程序中的 index.html 将使用每个网络应用程序的 css 文件夹中的 css 文件。
我尝试像这样使用路由并在 Controller 中使用重定向来呈现静态 html 页面:
Redirect("/webapp1/").withCookies(Cookie("token", "")).bakeCookies()
Redirect("/webapp2/").withCookies(Cookie("token", "")).bakeCookies()
GET /webapp1/ controllers.Assets.at(path="/public/webapp1", file="index.html")
GET /webapp1/*file controllers.Assets.at(path="/public/webapp1", file)
GET /webapp2/ controllers.Assets.at(path="/public/webapp2", file="index.html")
GET /webapp2/*file controllers.Assets.at(path="/public/webapp2", file)
index.html 将被正确路由和呈现。但是,文件夹中的 css 和图像未正确加载。 index.html 使用相对路径加载它们。然后以某种方式在顶层加载 css 和图像,例如 localhost/css/css1,而不是 localhost/webapp1/css/css1。
非常感谢您的建议。
比尔
最佳答案
尝试使用下面的路由来加载 css 和 javascript。
加载CSS:
/css/*file controllers.Assets.at(path="/public/css", file)
用于加载 Java 脚本:
/javascript/*file controllers.Assets.at(path="/public/css", file)
关于html - Play Framework : how to render static HTML pages with static js and css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53475514/