2017-04-07 64 views
1

我有以下代碼:陣營材料的UI菜單項containerElement不工作

<MenuItem primaryText="home" containerElement={<Link to="/" />} /> 

但它不能在其他主題/線程菜單項地方像這裏Material UI Menu using routes討論的解釋工作。 一旦我添加containerElement道具菜單項我得到這個異常:

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

你如何導入你的'鏈接'? – Andrew

+0

這是進口 '從'react-router'導入鏈接;' – comprex

+0

不確定是主要問題,但應該從'react-router'導入{鏈接};' – Andrew

回答

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>