javascript - React Redirect 重定向到错误的路径
问题描述
索引.js
<div className='col'>
<label htmlFor='link'> Link: </label>
<input type="text" name="link" id="link" className="form-control" readOnly value={ link } /> ===>>Link is something like https:www.google.com
</div>
路由.js
{ path: '/recommendation-edit/:id', name:'Recommendation Edit', component: RekkoEdit }
我想如果有人点击它重定向到该链接的链接。我试过Link
and Redirect
,但它们没有按预期工作。如果我使用其中任何一个,它会重定向到
http://localhost:3000/recommendation-detail/https://www.amazon.in/dp/B08445DF23/ref=cm_sw_r_cp_apa_i_RPBvFb596RQVR
而它需要重定向到
https://www.amazon.in/dp/B08445DF23/ref=cm_sw_r_cp_apa_i_RPBvFb596RQVR
解决方案
顾名思义,React 路由器用于路由 React 应用程序。您正在寻找的是普通的旧锚元素。所以只需使用:
<a href={link}>link</a>
代替Link
推荐阅读
- python - Python 3:使用带有列表 Windows 文件路径的正则表达式作为在特定位置具有数字的字符串
- angular - Angular 6:从子组件侧导航单击滚动到元素
- database - Oracle dB - 包含 GUI 到 dB 链接详细信息的系统表
- json - 从 JSON 响应中获取 TranscriptFileUri
- curl - 通过rest api创建k8s秘密时出错
- makefile - 使用 Makefile 仅在修改后的文件上运行脚本
- function - Rust 函数如何修改数组索引的值?
- kotlin - Kotlin - lambda 返回成员变量列表
- php - 如何向正则表达式添加规则
- javascript - 如何正确地让构造函数工作?