如何将 ID 属性添加到从 react-router link 标签呈现的锚标签?
How to add an ID attribute to the anchor tag that is rendered from react-router link tag?
// 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 时,我发现 Link 组件呈现了一个标签。所以我想知道如何将 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。
直接在tha link标签中添加ID属性即可:
<Link id="myId"></Link>
呈现的锚标记将包含提供给 link 标记的 ID 属性。
您还可以传递您想要出现的道具,例如标题、ID、类名等。
// 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 时,我发现 Link 组件呈现了一个标签。所以我想知道如何将 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。
直接在tha link标签中添加ID属性即可:
<Link id="myId"></Link>
呈现的锚标记将包含提供给 link 标记的 ID 属性。
您还可以传递您想要出现的道具,例如标题、ID、类名等。