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

Changing redirect url

I’m making discord login oauth2 in javascript, and I’ve set that when it’s done it redirects me on ‘/auth’, but when I’m on that page url has some other information in url, it’s like ‘/auth#token_type=Bearer&access_token=12ekasd&expires_in=123123&scope=identify’.. Is it possible to change that url so it says just ‘/auth’? I’ve tried with window.location.href = ‘/auth’ but nothing is being changed.

window.onload = () => {
  what to code here?
}

>Solution :

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

The history API allows you to update the URL shown without actually redirecting the page.

window.history.replaceState({}, '', window.location.pathname);

This code should redirect you to the current path but without any hash or query string.

If you need to use the hash or query string in your code, make sure to save them before running this, since it also removes them from window.location.

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