Home > Software design >  How to get new URL without having to redirect
How to get new URL without having to redirect

Time:11-08

So I am trying to grab a code that that appears in the URL when I redirect to a certain page. So I use something like window.location.href = URL. The issue is I have to do 2 redirects but the last one is the most important one because it routes to the page I want after I get the code from the first URL. So how do I grab the code from the first URL that it gives me without having to redirect?

When I redirect to a new page (AWS) what happens you can't run the rest of your javascript. The thing is I need to do 2 redirects. One to get the code in the the URL string that AWS gives me when I complete the redirect and another to take that code and generate a token using that code and redirect to the correct URL. But I can't do 2 redirects in a javascript function.

Login page --> need code from aws url after redirect --> redirect into my app after getting code from aws url

CodePudding user response:

check this out i think its what you are looking for

https://www.30secondsofcode.org/articles/s/javascript-modify-url-without-reload

CodePudding user response:

The first request should be an AJAX request

You posted no code or extra details about the server, however it's plain to see you need to be using AJAX concepts here and not rely on the browser bar and redirects.

  1. Make an AJAX request (the page does not redirect or reload)
  2. When the request completes, perform the logic you need to
  3. Finally redirect the user somewhere if it's still pertinent to do so

Welcome to the world of apps, because this is essentially what you're making: an app.

Read about AJAX: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

You can do it natively with vanilla JS, or many people prefer to use a 3rd-party library to manage this stuff... like Axios: https://axios-http.com

  • Related