0

I'm trying to redirect the page to Google's home page when user's logout. For that, I'm using the following function:

$(window.location)[0].replace(this.urlLogout);

But instead of being redirected to Google, I'm getting this route in the URL browser:

http://localhost:4200/www.google.com.br

Does anyone knows how to fix this problem?

Ali Esmailpor
  • 1,209
  • 3
  • 11
  • 22
  • Does this answer your question? [How to redirect to an external URL from angular2 route without using component?](https://stackoverflow.com/questions/40150393/how-to-redirect-to-an-external-url-from-angular2-route-without-using-component) – depperm Feb 03 '21 at 12:32
  • Seems you're redirecting relativley. How do you build `this.urlLogout`? – DonJuwe Feb 03 '21 at 13:05
  • this.urlLogout = this.$auth.estilo.des_url_logout; I'm getting this from an API that contains all the configuration informations, including the URL that will be redirected the website when logout.. – Cristhian Zanforlin Lousa Feb 03 '21 at 13:11
  • window.location.replace(this.urlLogout) this should work, make sure this.urlLogout has http:// or https:// if not you can add it client side or if you have control at API side then there. – Lokesh Daiya Feb 03 '21 at 14:22

2 Answers2

0

Seems like you are missing the protocol part, either try to get that from your API or you can do it on the client-side.

window.location.replace(`https://${this.urlLogout}`);

Or if you are sure about the protocol on your website and the redirecting domain and both of them are the same, you can do like this

window.location.replace(`${window.location.protocol}//${this.urlLogout}`);
Deepinder Singh
  • 729
  • 10
  • 18
0

window.location.replace(this.urlLogout) this should work, make sure this.urlLogout has http:// or https:// if not you can add it client side or if you have control at API side then there

@Lokesh Daiya

That worked for me, it was a missing http:// protocol in front of the URL. That's why I was getting this error.

Thank you!