我有这段代码,当id == 1时我想转发到另一个路径
get("/courses/{id}"){
val id = call.parameters["id"]?.toInt()
if (id is Int) {
if (id == 1)
// i want redirection to "/courses/top"
}
}
答案 0 :(得分:0)
您可以只使用call.respondRedirect
:
if (call.parameters["id"]?.toIntOrNull() == 1) {
call.respondRedirect("/courses/top")
}