Utilizing activatedRoute in Angular to retrieve encoded query parameters

I am facing an issue with my Angular application, where it is loaded after being redirected from another application. I need to access query parameters when the authentication website returns to my Angular application. The URL appears as:

http://localhost:4200/#/starterview?openId%3Dhttps:%2F%2Fmy.fidesque.net%2Fopenid%2Fyobtest_smeuser%26email%3Dyobtest@gml.nl%26userAuthMode%3DSP=

Despite trying

this.activatedRoute.snapshot.queryParams
, I am unable to retrieve the query parameters correctly. I suspect this might be due to the encoded params. Is there any workaround for this?

Kind regards, Venky

Answer №1

To reveal the hidden message in a coded URL, utilize the function decodeURIComponent as shared by Venky. If you possess the query parameters and wish to extricate the value from the decoded URL, employ this handy snippet:

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

For instance, if the URL appears like http://localhost:4200/login?username=jerry&code=1234, then

this.extractValueFromURLQuery('username'); // should yield 'jerry'

Answer №2

After implementing the code below, I successfully decoded the URL and was able to accurately extract the parameters.

const encodedUrl = 'http://example.com/#/starterview?openId%3Dhttps:%2F%2Fmy.example.net%2Fopenid%2Ftestuser%26email%<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="38474b47463c4e4d734949">[email protected]</a>%26userAuthMode%3DSP='
const decodedUrl = decodeURIComponent(encodedUrl);
console.log(decodedUrl);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to address observables in Angular in a manner similar to deferred objects

Transitioning from AngularJS to Angular has posed a challenge for me, especially when it comes to moving from promises to observables. Below is an example of my code in AngularJS: var deferred = $q.defer(), frame = document.createElement('newFrame ...

Troubleshooting: Directives in Angular 4 not recognizing RegEx patterns

I have developed a directive that validates the input in a text field, allowing users to enter numbers, dots, and commas. However, the validator only seems to work for numbers and not for commas and dots. import { Directive, ElementRef, HostListener } fro ...

Generating tables with ngFor in Angular 2

Is it possible to generate a table in Angular 2 with a dynamic number of columns by utilizing a loop based on the specified number? Specifically, how can we create a table without a fixed number of columns? ...

Retrieving Information from an Angular 2 Component

Struggling to figure this out, I am attempting to dynamically add user video data that includes a video URL. My goal is to access the data from the component so I can use it in my HTML. I've attempted the following approach. app.component.ts import ...

The issue with session storage persisting even after closing the iframe

Encountering a persistent issue where the sessionStorage remains populated even after closing an iframe and opening another one with the same destination. I assumed that the sessionStorage would be reset and start afresh each time. The iframe is contained ...

Proper method of retrieving a property as a designated type within a union type

I have a scenario where I need to return a specific property from a function in various parts of an application. This property can fall into one of two categories, each with string literal properties. One category is an extension of the other. How can I ...

What is the process for downloading a .docx file encoded in Base64?

Trying to download a .docx file received from the backend. The object being received is shown below: https://i.sstatic.net/nHKpn.png Download attempt using the following code: const blob = new Blob([fileSource.FileData], { type: fileSource.FileType }); ...

How can @ngrx be utilized to retrieve data based on the route?

Our webapp requires users to click through lists to reach a specific edit view. For example, starting from the landing page, a user selects a client, then an agent, and finally reaches the edit view of that agent. The URL in this scenario would contain the ...

Eliminate the X-Powered-By:express response header from the Angular UI navigation URL

When using the application, I am not seeing the header x-powered-by in the response headers, which is functioning as intended. The issue occurs when a user refreshes the page, causing the x-powered-by header to be added to the response header in the devel ...

Angular Material Spinner with Custom Image Icons - (mat-spinner)

I have successfully implemented the mat-spinner in my project with configurable changes like color and mode of spinning. However, I am now looking to add an image icon, specifically the logo of a brand or company, inside the spinner. How can I achieve this ...

Angular definitely typed does not convert into JavaScript

After installing TypeScript on my VS2013, I obtained the Angular 1.5 Definitely Typed from the NuGet package manager. Although angular.d.ts and its components do not generate angular.js file, when I create another TypeScript file like file1.ts, the file1. ...

Combining an Angular application within a Spring application and encountering a TypeError on a JSP page

I am currently working on integrating an Angular app into an existing Spring application. I have included the code for integration below. While it functions correctly on some JSP pages, it fails on others. Please see the description and rendered element in ...

Running a TypeScript file on Heroku Scheduler - A step-by-step guide

I have set up a TypeScript server on Heroku and am attempting to schedule a recurring job to run hourly. The application itself functions smoothly and serves all the necessary data, but I encounter failures when trying to execute a job using "Heroku Schedu ...

The floating filter in ag-Grid for Angular features a dropdown menu styled with Bootstrap

In my ag-grid table, I have a Bootstrap dropDownMenu displayed in CELL and in FLOATING FILTER. The issue arises when the dropdown menu is triggered - it gets hidden in the cell, as shown in the picture. https://i.sstatic.net/xBsPf.png To fix this proble ...

What is the best way to transform the date time format received from the server so that it can be used with the time-ago

Issue Explanation: My server is providing the date and time in a specific format as shown below - myDate2= '22-DEC-2017 03:22:11'; The current format does not work with time-ago-pipe and results in NaN Accepted Format: myDate: String = new Dat ...

Navigating product search in your Ionic Ecommerce App

Currently, I am working on developing an Ionic Ecommerce App with a large number of products that need to be displayed. However, I am facing a challenge when it comes to implementing the search functionality for these products within the Ionic App. After c ...

Show an array of arrays using a visual table representation

I am working with an Array of arrays in my data, and they are structured like this : https://i.sstatic.net/3grh6.png Now, I am trying to showcase this array in a table, but all I am getting is a blank page. Here is the HTML code for the table (I have incl ...

NestJS endpoint throwing a 500 error after submitting a post request

Struggling with sending post requests in NestJS as they are returning an error message: ERROR: An error occurred in POST /api/fraud-rules in 8ms... { "isError": true, "status": 500, "name": "InternalError", & ...

Get rid of the box-shadow that appears on the top side of mat-elevation

I placed a mat-paginator at the bottom of my mat-table which is styled with a mat-elevation-z4 class. However, when I added the mat-elevation-z4 class to the mat-paginator component as well, the upper shadow from the paginator appears to overflow onto the ...

Looking to personalize the MUI - datatable's toolbar and place the pagination at the top?

I successfully managed to hide the toolbar icon, but I am struggling with positioning pagination from bottom to top. Additionally, I am attempting to add two buttons (reset and apply) in the view-Column toolbar without any success in customizing the class. ...