Hi all, when using ktor, how can i redirect to another page and passing data? I have 2 pages (login and detail) and freemarker as template engine. On login page after form is submit, i would like to redirect to page detail
call.respondRedirect()
instead of rendering the new page
call.respondTemplate('detail.ftl', mapOf("myData" to myValue))
however i need to send some data to the new page when rendering the template
brabo-hi
06/28/2022, 12:10 AM
Copy code
post("/login") {
// Check everything is correct
val isSuccess = myRepository.process(username, password)
if (isSuccess) {
val uiMap = mapOf("key" to "value")
call.respondTemplate("detail", uiMap)
// Bellow is what i want to do, but i need to pass uiMap
// call.respondRedirect("/detail")
} else {
val uiMap = mapOf("key" to "username or password incorrect")
call.respondTemplate("detail", uiMap)
// Bellow is what i want to do, but i need to pass uiMap
// call.respondRedirect("/login")
}
}
brabo-hi
06/28/2022, 12:10 AM
PS: i don’t want to use session or cookie
a
Aleksei Tirman [JB]
06/28/2022, 7:53 AM
As another option, you can use query parameters.
b
brabo-hi
06/28/2022, 10:19 PM
@Aleksei Tirman [JB] what is the best way to pass query parameter with redirect