新秀在这里.有没有在React Router v4中使用indexLink的新方法?我正在更新一些版本3代码(我以为我离开了角度以避免所有这些弃用!)
我带来了一些解构:
var {NavLink, IndexLink} = require('react-router-dom');
Run Code Online (Sandbox Code Playgroud)
并使用IndexLink始终保持粗体:
<h2>Nav</h2>
<IndexLink to="/" activeClassName="active" activeStyle={{fontWeight: 'bold'}}>blah blah blah</IndexLink>
//Other navlinks working fine
Run Code Online (Sandbox Code Playgroud)
IndexLink是破坏我的代码的唯一因素,这是从我将其更改为时的错误.
"警告:React.createElement:类型无效 - 期望一个字符串(对于内置组件)或类/函数(对于复合组件)但得到:undefined.您可能忘记从其定义的文件中导出组件检查渲染方法
Nav."
一切都被导出,简单的应用程序完美运行,直到我添加IndexLink.现在传递出来.
以前,在react-router-dom v5(或更低版本)中,您可以使用:
<Route path="/" render={() => {doSomething(); return <ComponentName />}} />
既可以触发函数又可以创建路由,而无需在 ComponentName 组件内部创建任何额外的代码。render在 v6 中被替换为,element现在如何实现这一点?
如果我为某些组件设置了一个类名,比如
<Segment className="Change" color='blue' inverted></Segment>
Run Code Online (Sandbox Code Playgroud)
在我的 css 中我使用
.Change:hover{
background-color: black; //or any other change on hover
}
Run Code Online (Sandbox Code Playgroud)
悬停时没有任何内容被覆盖。
我还注意到有许多其他组件拒绝我的更改,似乎是随机的。一个语义组件会让我改变宽度,而下一个则不会。是同一个问题的原因吗?如何覆盖悬停时的颜色?