【发布时间】:2019-10-01 08:44:42
【问题描述】:
我是新来的反应。我试图通过单击一个按钮来重定向到一个组件,该按钮是现有渲染组件的一部分。 现在我希望当我单击按钮时,应该呈现新组件并且应该隐藏现有组件(按钮也是)。
render(){
return(
<div className='container'>
<table className='table table-striped'>
<thead>
<tr>
<th>User_Id</th>
<th>User_Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{this.state.arr.map((card)=>{
return(
<tr>
<td>{card.user_id}</td>
<td>{card.user_name}</td>
<td>{card.email}</td>
<td>
<button className="btn btn-outline-primary ml-2 my-2 my-sm-0">Edit</button>
//click here(the Edit button) to Redirect to another component
</td>
<td><button className="btn btn-outline-primary ml-2 my-2 my-sm-0">Delete</button></td>
</tr>
) })}
</tbody>
</table>
</div>
)
}
而要渲染的组件是-
export default class Edit extends Component{
render(){
return(
<div>
<h1>Edit User.</h1>
</div>
)
}
}
【问题讨论】:
-
请用路由
react-router-dom显示你的App.js
标签: javascript reactjs react-router jsx