简体   繁体   English

使用Play框架2重定向URL片段

[英]Redirect with URL fragment with Play framework 2

How can I add an URL fragment ( #xyz ) to a link created by the Redirect method? 如何将URL片段( #xyz )添加到由Redirect方法创建的链接中?

I want something like this: 我想要这样的东西:

Redirect(routes.Comment.get(itemId) + "#xyz")

You can get the url form the route using .url (which contains a relative url). 您可以使用.url(包含相对URL)获取路径的URL。 Redirect needs two parameters to accept a string to redirect to 重定向需要两个参数来接受要重定向到的字符串

so, Redirect(routes.Comment.get(itemId).url + "#xyz", SEE_OTHER) should work 所以, Redirect(routes.Comment.get(itemId).url + "#xyz", SEE_OTHER)应该工作

Edited when I realized Redirect() takes a Call and not a string 当我意识到Redirect()接受Call而不是字符串时编辑

使用Play Framework 2.4可以做到这一点:

Redirect(routes.Comment.get(itemId).withFragment("#xyz").toString)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM