如何使用查询字符串代替“;" [英] How to use the Querystring instead of ';'

查看:74
本文介绍了如何使用查询字符串代替“;"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个内部工具,供开发人员使用由C#WebApi支持的Angular2 beta 15.

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

随着新版本的发布,我升级了Angular2版本

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.

但是,Angular2在查询字符串之前包含可选参数,如下所示:

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

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

最初,我认为这是可以的,即使这不是我习惯的.但是,我现在遇到了需要潜在危险的Request.Path值"(例如"*")的情况(用于保存带有预先填充的正则表达式搜索字段的链接).

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. 用不同的符号代替*-表示开发人员必须知道特殊符号才能释放网址.
  2. URL对参数进行编码-意味着开发人员必须知道url编码值才能释放URL.
  3. 当这些参数具有特殊字符时将其排除-如果开发人员使用*释放URL,则页面仍会中断.
  4. 从预查询字符串参数切换为查询字符串参数.
  5. 手动控制查询字符串.

大多数简单的正则表达式在没有编码的查询字符串中都是完全有效的,这意味着(4)和(5)都是有效的解决方案.

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

(5)是可能的,但我无法想象我是唯一遇到此问题的人.如果存在正式的解决方案,我宁愿不创建自己的解决方法.

(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)是我的首选解决方案.我发现的许多较旧的示例在查询字符串中都显示了可选参数,因此我希望逻辑仍然存在,并且分号版本只是默认选项.

(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.

是否可以告诉路由器使用querystring参数,而不是它现在使用分号分隔的东西?

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

我同时搜索了angular.io和stackoverflow,找不到任何答案,也没有人问这个问题.

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

谢谢.

推荐答案

对于根路由器,可选参数在查询字符串中表示,对于子路由器,它们作为矩阵参数(显示的内容)添加

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

另请参见路由&导航

这篇关于如何使用查询字符串代替“;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆