Reactjs 如何使用带有语义ui菜单项的react router链接?
我有这个:Reactjs 如何使用带有语义ui菜单项的react router链接?,reactjs,react-router,semantic-ui,Reactjs,React Router,Semantic Ui,我有这个: <Link to="/"> <Menu.Item name='expense List' active={activeItem === 'expense List'} onClick={this.handleItemClick} /> </Link> 但我在控制台中得到一个错误: Warning: validateDOMNesting(...): <a> cannot appear as a descendant of
<Link to="/">
<Menu.Item name='expense List' active={activeItem === 'expense List'} onClick={this.handleItemClick} />
</Link>
但我在控制台中得到一个错误:
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
in a (created by MenuItem)
in MenuItem (at Header.js:26)
in a (created by Link)
in Link (at Header.js:25)
in div (created by Menu)
in Menu (at Header.js:22)
in div (at Header.js:20)
in Header (at AddExpense.js:8)
in div (at AddExpense.js:7)
in AddExpense (created by Route)
in Route (at index.js:20)
in Switch (at index.js:18)
in Router (created by BrowserRouter)
in BrowserRouter (at index.js:17)
in Routes (at index.js:30)
如何正确定义我的链接?材质UI中的每个菜单项都有一个单击道具。可以在onClick处理程序中使用此.props.history.push“/”:
<Menu.Item
name='expense List'
active={activeItem === 'expense List'}
onClick={() => this.props.history.push('/')} />
// You can also define the function outside and call history.push there
不过,您可能想使用withRouter。请参见材质UI中的每个菜单项都有一个单键道具。可以在onClick处理程序中使用此.props.history.push“/”:
<Menu.Item
name='expense List'
active={activeItem === 'expense List'}
onClick={() => this.props.history.push('/')} />
// You can also define the function outside and call history.push there
不过,您可能想使用withRouter。请参见您可以在语义组件中用作道具
...
import { Link } from "react-router-dom";
import { Menu } from "semantic-ui-react";
...
<Menu.Menu>
<Menu.Item as={Link} to="/path">Click me</Menu.Item>
</Menu.Menu>
...
您可以在Semanticu组件中用作道具
...
import { Link } from "react-router-dom";
import { Menu } from "semantic-ui-react";
...
<Menu.Menu>
<Menu.Item as={Link} to="/path">Click me</Menu.Item>
</Menu.Menu>
...
这是最佳答案-官方文件建议使用与react路由器相同的技术:这是最佳答案-官方文件建议使用与react路由器相同的技术: