0

Is there a way to redirect to a different url using Link to? This is the code I have written:

let obj = { key: 'google', title: 'Google link', link: 'www.google.com' }
let obj2 = { key: 'about', title: 'About', link: '/about' }
<Link target={obj.key === 'google' ? '_blank' : ''} to={obj.link}>{obj.title}</Link>

Here when I pass obj2 to Link ,it works as expected. From my current page (http://localhost:5000/contactus), it is navigated to http://localhost:5000/contactus page. I also want to redirect to 'www.google.com' but when I do that, it's redirecting to http://localhost:5000/www.google.com. Link to is building upon the parent url. I need it to link to google directly. How do I do it? 

Renee
  • 199
  • 12
  • You can not do this by Link tag, you can do - window.location.href = "https://www.google.com" – Rustam Ansari Jan 16 '23 at 13:14
  • if you use 'https:// link' it should work. `let obj = { key: 'google', title: 'Google link', link: 'https://www.google.com' }` because Link is transformed to an tag – mgm793 Jan 16 '23 at 13:16
  • @mgm793 thanks a lot for sharing the link. I am able to do as required with one of the answer posted. – Renee Jan 16 '23 at 13:24

0 Answers0