【发布时间】:2020-10-15 19:01:12
【问题描述】:
我正在创建一个具有用户配置文件的应用程序。如果用户决定删除他们的个人资料(通过单击“删除个人资料”按钮),它应该向我的后端服务器发送一个 DELETE 请求,然后将用户路由到我的应用程序的“/about”页面。我的代码结构如下:
import React, { Component } from "react";
import { render } from "react-dom";
class Profile extends Component {
constructor(props) {
super(props);
this.state = {
};
this.deleteProfile = this.deleteProfile.bind(this);
}
deleteProfile() {
// props contains all the necessary information to construct the request
// send request to backend server to delete the profile
// route to /about page
}
render() {
return (
<button onClick={this.deleteProfile}>Delete Profile</button>
);
}
}
export default Profile;
在用户单击“删除”按钮后,我无法找到有关如何将用户路由到 URL 的解决方案。有关如何执行此操作的任何建议?
【问题讨论】:
-
你用的是什么路由器?
-
我只是使用默认的 Django 路由(通过 urlpatterns)。下面的答案做了我需要的,谢谢!
标签: javascript reactjs url routes