Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In react component, location.href doesnt seem to redirect

I have a very simple scenario in which I need to redirect to an external domain in react something like this on change of a switch:

handleSwitch={() => {
                location.href = 'https://www.google.com/'; // oldAppUrl;
                    // window.open(oldAppUrl, '_href')
                }}

However, this is not working. What am I missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try like this:

window.location.href = 'https://www.google.com/';

and this should work too, using it in an app:

window.location = 'https://www.google.com/';

If none of these two works it means your handleSwitch function is probably not called, then you should show us some more code to help with the solving.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading