Material-ui: not compatible with react-router Link

Created on 23 Nov 2015  路  13Comments  路  Source: mui-org/material-ui

I tried to use Link with Menu Item and List Item. Both don't work. As Link is the main navigation for react-router, if it doesn't work, then how can I make -ui work with react-router?

None of the below worked

`<ListItem primaryText="All mail" >
      <Link to="/foo">foo</Link>
</ListItem>`

Then I wrap Link with ListItem, not working neither.
Try the same thing with MenuItem, both not working.

-- update 1
It is working now with following syntax. Case can be closed. I wish this is documented.
<MenuItem linkButton={true} containerElement={<Link to="/foo" />} primaryText="Foo" />

bug 馃悰

Most helpful comment

containerElement with react-router Link works fine with MenuItem but not in ListItem.

All 13 comments

@jma7889 Quite interesting question, but for now I can't see a bug here. Can we discuss on discordapp (Reactiflux/#material-ui) or on gitter?

@frankf-cgn did see some previous discussion regarding this. About to try if any of those works. Yes, we can discuss on discord app. It's not a bug, more of a feature request.

-- update 1
It is working now with following syntax
<MenuItem linkButton={true} containerElement={<Link to="/foo" />} primaryText="Foo" />

@jma7889 Otherwise you could just use Navigation mixin:

_handleLink: function(path) {
    this.transitionTo(path);
},
....
<ListItem primaryText="All mail"  onTouchTap={this._handleLink.bind(this, 'mail'}  />

Thanks @jma7889. Would be nice if documented.

@jma7889 If the right-icon-button or some other buttons in a listitem this way, for example:

<ListItem
  rightIconButton={<IconButton />}
  primaryText='some text'
  containerElement={<Link to={{pathname:"/"}} />

These buttons didn't work well.

I think, you made a mistake :
try this

<ListItem
  rightIconButton={<IconButton />}
  primaryText='some text'
  containerElement={<Link to="/"/>} />

containerElement with react-router Link works fine with MenuItem but not in ListItem.

@Paelsis This. Wondering if it's going to be fixed.

containerElement with react-router Link for TableRow would be helpful as well.

Are there any updates on this? Not even <MenuItem linkButton={true} containerElement={<Link to="/foo" />} primaryText="Foo" /> is working for me.

@Iambecomeroot

This is how it worked for me.

 <MenuItem key={i} component={Link} to='/somelink' >
                      {option.primaryText}
</MenuItem>

Source
https://stackoverflow.com/a/47875510

@zeeshan-za-ahmad Working for me. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

sys13 picture sys13  路  3Comments

ghost picture ghost  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

ericraffin picture ericraffin  路  3Comments