0

I have my server backend that is called from a client X(clickable link) with HTTP GET REQUEST this client send me values as RequestHeader, my need is to get these values (headers) and send it to My frontend (ANGULAR) and the most important thing is to get those values and continue my workflow.

the image below explain my workflow

enter image description here

this is my java code(spring controller)

private static final String NG_REDIRECT_URL= "http://localhost:4200";


@GetMapping(value = "/server-core")
    public RedirectView requestHandler(HttpServletRequest request, HttpServletResponse response,
            @RequestHeader(value = "user_id", required = true) String userId,
            @RequestHeader(value = "login", required = true) String login) throws IOException {
        return new RedirectView(NG_REDIRECT_URL, true);
    }
    
7
  • If you need to sent anything with a redirect, you’ll have to use query params in the url.. Commented Jan 24, 2021 at 17:31
  • something like this localhost:4200/list?login=login_value&user_id=user_value ???? if my provided example is correct how to intercept thoses params from angular app. THANK U Commented Jan 24, 2021 at 17:33
  • You can read those values from the ActivatedRoute snapshot.. reactgo.com/angular-get-query-params Commented Jan 24, 2021 at 17:37
  • thank u for ur response, but I try the ActivatedRoute inside the onInit method of app.component.ts (root component) and I get undefined value Commented Jan 24, 2021 at 17:42
  • Well you’re navigating to /list so I guess there is a list component? That is where you’ll have access to it.. Commented Jan 24, 2021 at 17:45

1 Answer 1

1

You need add the values as query parameters in the url of the angular and you need to get those parameters in app.component.ts with the help of following and do your operations with the values

ngOnInit() {
     const url = window.location.href;
     if (url.includes('?')) {
        const httpParams = new HttpParams({ fromString: url.split('?')[1] });
        const token = httpParams.get("token");
        //Here you will have you operations and you navigation with the parameters
        //this.router.navigate(['/home']);
     } else {
        //Here you will have your actual redirection
     }
}

And avoid using empty path redirection in routing module (ex. app.routing-module.ts).Try manual navigation to the page in app.component.ts

I think this will help you...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.