'Url redirect adds "localhost" to front of url
My prop linkUrl = www.google.com
I'm trying to redirect to www.google.com with the following code:
window.location.href = `${linkUrl}`;
and
window.open(`${linkUrl}`)
However, when I click on the button, I'm redirected to the following URL:
http://localhost:3000/www.google.com
For some reason, the code adds localhost before the url
Solution 1:[1]
www.google.com is a relative uri, because it doesn't have a scheme. These relative uris are expanded as http://current-domain/current-path/www.google.com.
To make this an absolute URI, it needs to look like this:
https://www.google.com/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Evert |
