我有以下代码:
<MenuItem primaryText="home" containerElement={<Link to="/" />} />
但是它没有像其他主题/线程中所解释的那样,其中MenuItem在这里讨论Material UI Menu using routes。 一旦我将menuElement prop添加到MenuItem,我就会遇到这个异常:
Uncaught Error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
You likely forgot to export your component from the file it's defined in.
Check the render method of `EnhancedButton`.
答案 0 :(得分:2)
看起来不再有效(需要找到更改日志。)
为了解决这个问题,我做了npm install react-router-dom --save
并使用了以下代码段:
import React, { Component } from 'react';
import { NavLink } from 'react-router-dom'
import Menu from 'material-ui/Menu';
import MenuItem from 'material-ui/MenuItem';
import Drawer from 'material-ui/Drawer'
<Drawer
docked={false}
open={this.state.open}
onRequestChange={(open) => this.setState({open})}>
<MenuItem onTouchTap={() => {this.handleClose()}} >
<NavLink to="/">Home </NavLink>
</MenuItem>
<MenuItem onTouchTap={() => {this.handleClose() }} >
<NavLink to="/about"> About Us </NavLink>
</MenuItem>
</Drawer>