redirectTo 有效,但在 IHP 中不会更改 URL

redirectTo works but does not change URL in IHP

上下文

我有 2 个控制器:

根据生成的控制器代码,在 LessonsControllerShowLessonAction 呈现 ShowView

ShowView 中,我有一个 link 到 QuizAnswersController 中的一个动作:

<a href={CheckQuizAnswerAction (get #id answer)}>Check Answer</a>

CheckQuizAnswerAction 检查答案是否正确,然后重定向到 ShowLessonAction 并显示成功消息:

action CheckQuizAnswerAction { quizAnswerId } = do
    quizAnswer <- fetch quizAnswerId
    quiz <- fetch (get #quizId quizAnswer)
    let lessonId = get #lessonId quiz

    case (get #correct quizAnswer) of
        True -> setSuccessMessage "Correct!" >> redirectTo ShowLessonAction { lessonId }
        False -> setSuccessMessage "Try again" >> redirectTo ShowLessonAction { lessonId  }

问题

一切正常,但我注意到在调用 CheckQuizAnswerAction 之后,URL 是:

/CheckQuizAnswer?quizAnswerId=123...

而不是:

/ShowLesson?lessonId=123...

是什么让这项工作与不同的 URL 一起工作?

由于您的操作有副作用,因此最好在此处使用表格:

<form method="POST" action={CheckQuizAnswerAction (get #id answer)}>
    <button type="submit" class="btn btn-link">Check Answer</button>
</form>

使用这个代替 <a href={CheckQuizAnswerAction (get #id answer)}>Check Answer</a> 可能已经解决了问题:)