// modules/App.js <li><Link to="/about" activeStyle={{ color: 'red' }}>About</Link></li> <li><Link to="/repos" activeStyle={{ color: 'red' }}>Repos</Link></li>
当使用 Chrome 开发者工具检查 DOM 时,我发现链接组件呈现了一个标签。所以我想知道如何向生成的标签添加 id 属性
<a id="foo">
i have tried this but it didn't work :
<li><Link id="foo" to="/about" activeStyle={{ color: 'red' }}>About</Link></li>
最佳答案
来自文档:
You can also pass props you'd like to be on the such as a title, id, className, etc.
http://knowbody.github.io/react-router-docs/api/Link.html
您使用的是哪个版本的react-router。通过使用开发控制台检查元素,确保 id 未呈现。
关于javascript - 如何向从react-router链接标签呈现的 anchor 标签添加ID属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41955664/