gpt4 book ai didi

reactjs - 如何为每个 Material-UI TableRow 添加 react 路由器?

转载 作者:行者123 更新时间:2023-12-03 13:26:46 27 4
gpt4 key购买 nike

How to add link per TableRow in .map?

*my error is validateDOMNesting(...): cannot appear as a child of "< a >" im using react router react-router-dom

how to add link in every loop of .map in Table TableRow?

   import React, { Fragment } from 'react'
import { Paper } from 'material-ui'
import Table from 'material-ui/Table';
import TableBody from 'material-ui/Table/TableBody';
import TableCell from 'material-ui/Table/TableCell';
import TableHead from 'material-ui/Table/TableHead';
import TableRow from 'material-ui/Table/TableRow';
import { connect } from 'react-redux'
// import { Edit, Delete } from '@material-ui/icons'
import { withStyles } from 'material-ui/styles'
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
const drawerWidth = 100;
class Listofbond extends React.Component {
render() {
console.log(this.props);
const { MainProps, classes } = this.props;
return (
<Router>
<Paper>
<Table >
<TableHead>
<TableRow>
<TableCell>Bondame</TableCell>
</TableRow>
</TableHead>
<TableBody>
{[1, 2, 3].map(n => {
return (
<Link to={`/bond/${n}/`} key={n}>
<TableRow>
<TableCell component="th" scope="row">
{n}
</TableCell>
</TableRow>
</Link>
);
})}
</TableBody>
</Table>
</Paper>
</Router>
)
}

}

export default Listofbond;

最佳答案

正确的方法是使用 TableRow 组件的 component 属性:

<TableRow component={Link} to={`/bond/${n}/`} key={n}>
...
</TableRow>

关于reactjs - 如何为每个 Material-UI TableRow 添加 <Link> react 路由器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50691049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com