rel1x
rel1x

Reputation: 2441

Redirect to external or internal link

I have a page in my application where backend decides where user should be redirected next. And it can be external link like 'google.com' or internal '/'. I use useNavigate hook from react-router-dom.

import { useNavigate } from "react-router-dom";
import axios from "axios";

useEffect(async () => {
  await axios.get().then((response) => {
    navigate(axios.redirectLink);
  });
});

It perfectly works for internal links, but doesn't work for navigate('https://google.com'). Then it tries to open https://my-website/https://google.com. What might be a solution here?

Upvotes: 0

Views: 812

Answers (1)

Meet Majevadiya
Meet Majevadiya

Reputation: 365

There is no solution in navigating if you want a use Link tag do that else you can check this link as well

React-Router open Link in new tab

<Link to="your url" target="_blank">Test</Link>

Upvotes: 1

Related Questions