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:
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With