dan*_*mcr 1 javascript node.js reactjs react-router
我的 React 应用程序中有一个<p>标签,我想在其中渲染 React Router V4 链接。目前,它不返回 Link,而是返回[object Object].
这是我的代码:
<p className="pt2 pb4">
{`We are constatly encouraging people to get involved, as clichue as it sounds, Rendah is about community, so wether youre an artist, a designer, a writer, a developer or anything else and want to get involed? ${<Link to={'/Contact'} className="no-underline link">Please get in touch!</Link>}`}
</p>
Run Code Online (Sandbox Code Playgroud)
我搜索了几个问题,但似乎没有一个问题能够复制或解决我在这里遇到的问题。我错过了什么吗?
如有任何帮助/建议,我们将不胜感激 - 提前谢谢您。
您正在连接为字符串,因此它会转换为字符串!将对象与字符串连接时,通过类型强制调用 toString() 方法,该方法将始终返回 [object Object]。使用 JSX 时,不必将文本包装在字符串中,相反,当嵌套在组件内时,文本和组件可以是同级的。
尝试:
<p className="pt2 pb4">
We are constatly encouraging people to get involved, as clichue as it sounds, Rendah is about community, so wether youre an artist, a designer, a writer, a developer or anything else and want to get involed <Link to={'/Contact'} className="no-underline link">Please get in touch!</Link>
</p>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2441 次 |
| 最近记录: |