-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Router Links
and MenuItems
#142
Comments
This should be handled in #319. |
This was solved by component augmentation, #414. <Menu.Item as={Link} to='/home' /> See the docs for more. |
This information was difficult to find. A google search to landed me here. Where can I find this information in the docs? |
This example can be found on the main page of docs 😞 |
Thanks! Suggestion: Being that the concept of Augmentation "is essential for working with MenuLinks and react-router" can we at least include a link to the Augmentation documentation within the "See" list located at the top of to the Menu page? 😁 |
How can I do this in a card group passing down props? It is clear where to put the |
I have the same question as @hariDasu. Did you ever figure this out? I can't find your stack overflow question. |
@RobertShaw1 this sounds like a great idea! I would even go for a PR that adds a React Router example. The docs already use React Router. Would you like to contribute the PR? |
But how can we achieve |
@m-adil I am also looking for a solution to this, although I believe the problem is with the onClick being overridden by the Link component changing the route and not continuing on to complete the Menu.Item onClick prop. Any suggestions? <Menu pointing>
<Menu.Item as={Link} to="/" name='home' active={this.state.activeItem === 'home'} onClick={this.handleItemClick}/>
<Menu.Item as={Link} to="/products" name='products' active={this.state.activeItem === 'products'} onClick={this.handleItemClick}/>
</Menu> |
@ThisIsRuddy Yeah. I also didn't get any fix for |
Ah I will have a look when I'm back later on today but I think a better
way would be to check the current url slug to set the active flag rather
than relying on the onclick event
…On Sat, 3 Feb 2018, 12:07 Adil Mazhar, ***@***.***> wrote:
@ThisIsRuddy <https://github.com/thisisruddy> Yeah. I also didn't get any
fix for <Menu.Item> yet but in order to achieve the functionality, I've
adopted NavLink from react-router-dom
<https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/NavLink.md#navlink>.
Hope this would help.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABrfk_Fkr67QtJp3p_dQH4EElsVxBqGTks5tREwYgaJpZM4G_39G>
.
|
NavLink works <Menu.Item as={NavLink} to="/messages" content="Messages"/> But, as you navigate it doesn't re-evaluate the state of the menus, so the active indicator only changes if you reload the page |
@ThisIsRuddy @m-adil To be clear, |
@duanefields @ThisIsRuddy @m-adil, If you don't pass const Nav = props => (
<NavLink
exact
{...props}
activeClassName="active"
/>
); Use it like below. Less code, less clutter. const Navigation = () => (
<Menu secondary>
<Menu.Item as={Nav} to="/" name="home" />
<Menu.Item as={Nav} to="/about" name="messages" />
<Menu.Item as={Nav} to="/sample" name="friends" />
</Menu>
); |
@entrptaher I ended up just wrapping it with "withRouter" and that fixed it import React, { Component } from 'react'
import { Container, Image, Menu } from 'semantic-ui-react'
import { NavLink, withRouter } from 'react-router-dom'
import { observer, inject } from 'mobx-react'
@inject('UIStore')
@observer class NavigationMenu extends Component {
render() {
let user = this.props.UIStore.user
return (
<Menu fixed='top' inverted>
<Container>
<Menu.Item header>
<Image
size='mini'
src={`${process.env.PUBLIC_URL}/glg-logo-white.png`}
style={{ marginRight: '1.5em' }}
/>
Postmaster
</Menu.Item>
<Menu.Item as={NavLink} exact to="/" content="Status"/>
<Menu.Item as={NavLink} to="/queue" content="Hold Queue"/>
<Menu.Item as={NavLink} to="/messages" content="Messages"/>
<Menu.Item as={NavLink} to="/stats" content="Stats"/>
{ user && (
<Menu.Menu position="right">
<Menu.Item name={user.name} content={user.name}/>
</Menu.Menu>
)}
</Container>
</Menu>
)
}
}
export default withRouter(NavigationMenu) |
ran into issues with trying to wrap
MenuItem
s in react-routerLink
s and vice-versa.Link
components do not play nice withMenuItem
components, because they are both rendered asa
tags in the dom, here is how it looks when elements are rendered:this causes issues with styling, and breaks behaviors with
MenuItem
The text was updated successfully, but these errors were encountered: