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 :
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?
CodePudding user response:
To follow-up on my comment, you can encode the dates
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, because :dates
is no longer part of the path, it is now an optional parameter:
path: 'approve/:vacation/:id/:vacationsLeft