首页 > 解决方案 > 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 }

我想如果有人点击它重定向到该链接的链接。我试过Linkand 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

标签: javascriptreactjsreact-router-dom

解决方案


顾名思义,React 路由器用于路由 React 应用程序。您正在寻找的是普通的旧锚元素。所以只需使用:

<a href={link}>link</a>

代替Link


推荐阅读