deamon
deamon

Reputation: 92407

Redirect with URL fragment with Play framework 2

How can I add an URL fragment (#xyz) to a link created by the Redirect method?

I want something like this:

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

Upvotes: 3

Views: 775

Answers (2)

faster2b
faster2b

Reputation: 672

With Play Framework 2.4 is possible do this:

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

Upvotes: 2

johanandren
johanandren

Reputation: 11479

You can get the url form the route using .url (which contains a relative url). Redirect needs two parameters to accept a string to redirect to

so, Redirect(routes.Comment.get(itemId).url + "#xyz", SEE_OTHER) should work

Edited when I realized Redirect() takes a Call and not a string

Upvotes: 2

Related Questions