首页 > 解决方案 > 反应网址重定向

问题描述

所以我正在制作一个课程管理应用程序,它允许我呈现特定课程的模块列表和特定模块的课程列表。当我尝试删除特定课程时,我在客户端的服务文件会尝试获取我刚刚删除的课程的 url。这会导致“未处理的拒绝(SyntaxError):JSON 输入意外结束”错误。我的朋友建议我使用“this.props.history.push”来从 url 中删除课程部分,然后重新加载包含模块的 url。

这是我删除课程的功能:

deleteLesson(lessonId) {
    let popupWindow = window.confirm("Are you sure you want to delete this lesson?");
    if (popupWindow) {
        this.lessonService
            .deleteLesson(lessonId)
            .then(() => {
                this.findAllLessonsForModule(this.state.courseId, this.state.moduleId);
                this.props.history.push(`http://localhost:8080/course/${this.state.courseId}/module/${this.state.moduleId}`);
            });
    }
}

我在这里所做的是,一旦我删除了具有特定课程 ID 的课程,我会再次重新加载该模块的所有课程,之后我想更改 URL。

我该怎么办?

标签: reactjs

解决方案


推荐阅读