2012-10-15 45 views
1

我已经定义了以下路线文件的URL摆脱了最初的HTML页面:发挥framework2:获得

GET /   controllers.Application.app 

# web service entries... 
GET  /api/users controllers.Users.list 
[...] 

# Map static resources from the /public folder to the /assets URL path 
GET  /*file  controllers.Assets.at(path="/public", file) 

,在我Application.app行动我只是重定向到index.html的

def app = Action { 
    Redirect(routes.Assets.at("index.html")) 
} 

所以当我在http://mydomain访问我的申请,我重定向到http://mydoamin/index.html,然后添加/#想法的位置(这是一个单一的网页应用程序)

我想摆脱index.html文件,而是被重定向到http://mydoamin/#ideas

是否有可能?

回答

2

使用此在你的路由文件:

GET / controllers.Assets.at(path="/public", file="index.html") 

所以你不需要接触任何控制器。

+0

是的,你是对的:-)这是如此简单,我没有考虑它;-) –

+0

小菜一碟,谢谢! – opensas

1

只是一个指针:您可以尝试从资产控制器获取Html代码,然后返回带有Html内容的Ok结果。

为此,您可以尝试查看test helpers中如何调用控制器,以及如何获取此调用的结果和正文。

粗略地(未测试):

def app = Action { 
    request => { 
     val result = controllers.Assets.at("public","index.html")(request) 
     val html = contentAsString(result) 

     Ok(html) 
    } 
} 
+0

我收到了一个'not found:value contentAsString'。我错过任何导入吗?我得到的只是play.api._和导入play.api.mvc._ – opensas

+0

啊对不起,它来自play.api.test.Helpers类。但由于您无法在主Play应用中使用它,因此您必须改用“result.body”。 –