Home > Enterprise >  Changing redirect url
Changing redirect url

Time:10-05

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?
}

CodePudding user response:

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.

  • Related