Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the Querystring instead of ';'

I have been writing an internal tool for use by developers using Angular2 beta 15 backed by a C# WebApi.

I up the Angular2 version as new versions are released

I have been using routing from day 1 but now I need to add optional parameters. Typically this is done via the querystring.

However, Angular2 includes optional parameters before the querystring like so:

http://www.example.com;a=b;c=4

Originally I figured that would be fine, even though it isn't what I am used to. However, I have now run into cases where I need to have "potentially dangerous Request.Path value[s]" such as "*" (for saving links with a regular expression search field pre-populated).

I can think of several fixes including:

  1. Substitute a different symbol for * - Means that developers must know the special symbol in order to free hand a url.
  2. Url encode the parameters - Means that developers must know the url encoded value to free hand a url.
  3. Exclude those parameters when they have special characters - the page still breaks if a developer free hands the url using *.
  4. Switch from pre-querystring parameters to querystring parameters.
  5. Manually control the querystring.

Most simple regular expressions are perfectly valid in the querystring without encoding, this means that both (4) and (5) are valid solutions.

(5) is possible, but I can't imagine I am the only one who has run into this issue. I would rather not create my own workaround if an official solution exists.

(4) is my preferred solution. Many of the older examples I have found show the optional parameters in the querystring, so I hope that the logic still remains and that the semi-colon version is simply the default option.

Is it possible to tell the router to use querystring parameters instead of the semi-colon delimited stuff it does now?

I searched both angular.io and stackoverflow and could not find any answers or anyone asking this question.

Thanks.

like image 536
JALLRED Avatar asked Apr 14 '16 19:04

JALLRED


2 Answers

You can try this:

<a [routerLink]="['/users']" [queryParams]="{q:'ABC', location:2929}">Test</a>

This will give you a route like http://www.example.com/users?q=ABC&location=2929

Good Luck.

like image 173
Aakash Avatar answered Nov 07 '22 18:11

Aakash


For the root router optional parameters are represented in the querystring, for child routers they are added as matrix parameters (what you showed)

See also ROUTING & NAVIGATION

like image 38
Günter Zöchbauer Avatar answered Nov 07 '22 19:11

Günter Zöchbauer