我按照以下方式拥有一个Material ui菜单:
我可以在MenuItem中添加一个属性来渲染
以下代码会抛出错误。
错误:元素类型无效:期望为字符串(用于内置组件)或类/函数(用于复合组件),但得到了对象。
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
<Menu id="simple-menu" anchorEl={anchorEl} keepMounted open={!!anchorEl} onClose={handleClose}>
<MenuItem onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={handleClose}>Log Out</MenuItem>
</Menu>
我想使用 next.js 的 Link
标签与 MenuItem
一起使用,最好的方法是什么?
我尝试了以下内容:
下面的代码不会渲染出 <a>
标签,但会将 href 添加到 <li>
标签中。
<Link href={'#'} passHref><MenuItem onClick={handleClose}>Log Out</MenuItem></Link>
我可以在MenuItem中添加一个属性来渲染
<a>
而不是<li>
标记,但由于菜单嵌套在<ul>
标记下,我不确定是否将<ul><a>Log Out</a></ul>
作为好方法。
以下代码会抛出错误。
<MenuItem onClick={handleClose} component={<Link href={'#'}>Log Out</Link>}></MenuItem>
错误:元素类型无效:期望为字符串(用于内置组件)或类/函数(用于复合组件),但得到了对象。
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
<Link />
组件上不存在style
。 - Duderino9000<Link style={{textDecoration: 'inherit', color: 'inherit'}}>
。 - icio