我一直在尝试在单击按钮时对另一个组件进行简单的重定向,但由于某种原因它不起作用。我想重定向到“/仪表板”并从登录显示 AdminServices,如下所示:
//index.js
ReactDOM.render(<BrowserRouter><App /></BrowserRouter>,
document.getElementById("root"));
Run Code Online (Sandbox Code Playgroud)
//App.js
<Switch>
<Route path="/" component={Login} />
<Route path="/dashboard" component={AdminServices} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
//登录.js
<Button
onClick={this.login}
>
</Button>
login = () =>{
<Redirect to="/dashboard" />
}
Run Code Online (Sandbox Code Playgroud)
//AdminServices.js
render(){
return(
<div>Test</div>
);
}
Run Code Online (Sandbox Code Playgroud) 我使用 Material UI 制作了一个表格,其中每行的第一列都有两个按钮。我希望在单击这些行时编辑/删除行,但我坚持逻辑。我的实施是否有可能?如果不是,那么首选的做法是什么?
render() {
var deleteIcon =
(<IconButton onClick={console.log("delete")}>
<DeleteIcon color="secondary" />
</IconButton>
);
const editIcon = (
<IconButton onClick={console.log("edited")}>
<EditIcon color="primary" />
</IconButton>
);
return(
<TableBody>
{this.state.serviceData.map(n => {
return (
<TableRow key={n.id}>
<TableCell style={styles.editor} component="th" scope="row">
{deleteIcon}
{editIcon}
</TableCell>
<TableCell>{n.domain}</TableCell>
<TableCell>{n.service_name}</TableCell>
</TableCell>
</TableRow>
)};
Run Code Online (Sandbox Code Playgroud)