reactjs - 反应网址重定向
问题描述
所以我正在制作一个课程管理应用程序,它允许我呈现特定课程的模块列表和特定模块的课程列表。当我尝试删除特定课程时,我在客户端的服务文件会尝试获取我刚刚删除的课程的 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。
我该怎么办?
解决方案
推荐阅读
- python - 匹配熊猫数据框中的日期时间 YYYY-MM-DD 对象
- java - 线程“Thread-2”中的异常 java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) 用于 PACT 测试
- javascript - 使用反应上下文 api 从帮助函数显示加载器
- azure-devops - 基于 Azure Devops 中的特定状态冻结工作项的表单或页面上的所有字段的技术
- angular - Angular combineLatest:combineLatest 中允许多少订阅?订阅数量有限制吗?
- node.js - Node.js 中多人游戏的时机
- php - 如何从 web api 获取 json 数据到 android 应用程序?
- python - 正则表达式python中的多个匹配词
- typo3 - Typo3 9.5:停用 Slugs 并改用 id=123?
- ocaml - 在一个独立的 ocaml 程序中断言