我如何重定向另一条路

时间:2019-08-10 14:08:32

标签: kotlin ktor

我有这段代码,当id == 1时我想转发到另一个路径

get("/courses/{id}"){
    val id = call.parameters["id"]?.toInt()
    if (id is Int) {
        if (id == 1)
        // i want redirection to "/courses/top"
    }
}

1 个答案:

答案 0 :(得分:0)

您可以只使用call.respondRedirect

if (call.parameters["id"]?.toIntOrNull() == 1) {
    call.respondRedirect("/courses/top")
}