Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to accept Querystring from URL into Angular route?

I need to accept this format of URL into my Angular app:

http://localhost:4200/approve/VA/28/20/0=2022-02-02&1=2022-02-03&2=2022-02-04

My route path is this

path: 'approve/:vacation/:id/:vacationsLeft/:dates'

Unfortunately when I visit the URL I get :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

http://localhost:4200/approve/VA/28/20/0

I am getting the URL from an email and I can’t change the format of the query. Is there a way to pass it into Angular route?

>Solution :

To follow-up on my comment, you can encode the date URL parameters with something like this:

let vacactionCode = 'VA';
let vacationId = 28;
let vacationsLeft = 20;
let dates = encodeURIComponent("0=2022-02-02&1=2022-02-03&2=2022-02-04");

let url = `http://localhost:4200/approve/${vacactionCode}/${vacationId}/${vacationsLeft}?dates=${dates}`;

Then you would need to update your route to:

path: 'approve/:vacation/:id/:vacationsLeft

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading