4

I have angular application which is loaded after redirecting from another application. I want to access query params when authentication website returns to my Angular application. The url looks like

http://localhost:4200/#/starterview?openId%3Dhttps:%2F%2Fmy.fidesque.net%2Fopenid%2Fyobtest_smeuser%26email%[email protected]%26userAuthMode%3DSP=

I want to access the query params but I am not able to do it correctly using this.activatedRoute.snapshot.queryParams I suspect that it is due to encoded params. Is there any workaround ?

regards, Venky

2
  • What does "I am not able to do it correctly" mean? What is your code, what do you expect it to do and what does it do instead? Why does the website uses such a horrible parameter name, without any value? Commented Nov 18, 2017 at 15:52
  • Same problem here, Angular cannot retrieve my query params. Any solution ? Commented Nov 8, 2018 at 15:21

2 Answers 2

3

You can decode the encoded URL using decodeURIComponent as answered by Venky. If you know the query params and want to extract the value from decoded URL. Use this function:

getQueryParamFromMalformedURL(name) {
    const results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(decodeURIComponent(this.router.url)); // or window.location.href
    if (!results) {
        return 0;
    }
    return results[1] || 0;
}

If the url is http://localhost:4200/login?username=jerry&code=1234, then

this.getQueryParamFromMalformedURL('username'); // should return 'jerry'
Sign up to request clarification or add additional context in comments.

Comments

2

I decoded the URL using following code. Then I could extract the params correctly

const encodedUrl = 'http://localhost:4200/#/starterview?openId%3Dhttps:%2F%2Fmy.fidesque.net%2Fopenid%2Fyobtest_smeuser%26email%[email protected]%26userAuthMode%3DSP='
const decodedUrl = decodeURIComponent(encodedUrl);
console.log(decodedUrl);

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.