2

trying to navigate the users to differrent websites upon registration

handleSubmit = () => {
code
if(registered){
Navigate to external link
}
    }

Im trying to use <Link to={{ pathname: 'res.data.storeRegistrationLink' }}/> but its not working.

5 Answers5

2

Try this and let me know if you face any issues. Here you can use window.location.replace too while i write window.location because it allows the user to go back to the route that redirected them.

 handleSubmit = () => {   if(registered){  window.location.href = 'https://google.com';  }}
sohaib
  • 574
  • 5
  • 16
0

Use this code:

window.location.href === `${res.data.storeRegistrationLink}`
Moein Moeinnia
  • 1,945
  • 3
  • 10
  • 26
0

if you're using react-router-dom you can easily redirect the user after the condition is true like the following:

handleSubmit = () => {
    code
    if(registered){
        <Redirect to="/somewhere/else" />
    }

}

0

You could maybe use the link tag from react router dom in this way.

<Link to='/'></Link>

Just but your desired link in the to attribute.

Wayne Celestin
  • 149
  • 1
  • 6
0

You can use window object for this like below

 handleSubmit = () => {
    some code
    if(registered){
    window.open(res.data.storeRegistrationLink, "_blank")
    }
   }
Mukesh Maurya
  • 340
  • 4
  • 16