首页 > 解决方案 > 我如何重新定向另一条路径

问题描述

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

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

标签: kotlinktor

解决方案


您可以使用call.respondRedirect

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

推荐阅读