简体   繁体   English

使用React Semantic UI使用NavLink设置活动页面类?

[英]With React Semantic UI use NavLink to set active page class?

Im using Semantic UI React and React Router. 我使用Semantic UI React和React Router。 The NavLink componenet from React Router knows then its the active page link and can set an active class: 来自React Router的NavLink组件知道其活动页面链接并可以设置活动类:

<NavLink to="/" exact activeClassName="active">Home</NavLink>

However this doesn't work with Semantic UI React: 但是,这不适用于语义UI反应:

    <Menu.Item
      header
      as={NavLink}
      to="./"
      children="Diplomat"
      activeClassName="active"
    />

I can see in the browser that the aria-current property is being set to true correctly. 我可以在浏览器中看到aria-current属性正确设置为true。 So NavLink does 'know' when its active but I cant pass this to Menu.Item. 因此NavLink确实“知道”它的活动时间,但我无法将其传递给Menu.Item。

I made a mistake. 我犯了一个错误。 I just needed an exact attribute and a different path. 我只需要一个exact属性和一个不同的路径。 Now it works. 现在它有效。

<Menu.Item header as={NavLink} exact to="/" children="Diplomat" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM