“点”在查询字符串参数- AngularJS。

时间:2021-09-01 13:16:47

I'm trying to use dot (.) in query string parameter but its not working.

我试图在查询字符串参数中使用dot(.),但它不起作用。

This URL is working fine:

这个URL运行良好:

http://localhost:9000/search-result?majTFMin=0&majTFMax=100&majDOMCFMin=0&majDOMCFMax=100&majRefDomainsMin=0&majRefDomainsMax=100&majRefIPsMin=0&majRefIPsMax=100&majRefDomainsEDUMin=0&majRefDomainsEDUMax=100&majRefDomainsGOVMin=0&majRefDomainsGOVMax=100&selectedTLDs=com

http://localhost:9000 /搜索结果? majTFMin = 0 &majtfmax = 100 &majdomcfmin = 0 &majdomcfmax = 100 &majrefdomainsmin = 0 &majrefdomainsmax = 100 &majrefipsmin = 0 &majrefipsmax = 100 &majrefdomainsedumin = 0 &majrefdomainsedumax = 100 &majrefdomainsgovmin = 0 &majrefdomainsgovmax = 100 &selectedtlds = com

But not this one as it contains a dot in a parameter:

但不是这个,因为它在参数中包含一个点:

http://localhost:9000/search-result?majTFMin=0&majTFMax=100&majDOMCFMin=0&majDOMCFMax=100&majRefDomainsMin=0&majRefDomainsMax=100&majRefIPsMin=0&majRefIPsMax=100&majRefDomainsEDUMin=0&majRefDomainsEDUMax=100&majRefDomainsGOVMin=0&majRefDomainsGOVMax=100&selectedTLDs=co.uk

http://localhost:9000 /搜索结果? majTFMin = 0 &majtfmax = 100 &majdomcfmin = 0 &majdomcfmax = 100 &majrefdomainsmin = 0 &majrefdomainsmax = 100 &majrefipsmin = 0 &majrefipsmax = 100 &majrefdomainsedumin = 0 &majrefdomainsedumax = 100 &majrefdomainsgovmin = 0 &majrefdomainsgovmax = 100 &selectedtlds =增加

When I'm trying to open above URL (with dot), it just prints:

当我尝试打开上面的URL(带点)时,它会输出:

Cannot GET /search-result?majTFMin=0&majTFMax=100&majDOMCFMin=0&majDOMCFMax=100&majRefDomainsMin=0&majRefDomainsMax=100&majRefIPsMin=0&majRefIPsMax=100&majRefDomainsEDUMin=0&majRefDomainsEDUMax=100&majRefDomainsGOVMin=0&majRefDomainsGOVMax=100&selectedTLDs=co.uk

无法获得/搜索结果? majTFMin = 0 &majtfmax = 100 &majdomcfmin = 0 &majdomcfmax = 100 &majrefdomainsmin = 0 &majrefdomainsmax = 100 &majrefipsmin = 0 &majrefipsmax = 100 &majrefdomainsedumin = 0 &majrefdomainsedumax = 100 &majrefdomainsgovmin = 0 &majrefdomainsgovmax = 100 &selectedtlds =增加

And nothing else, not even any HTML tags(has checked that in view source)

没有别的,甚至连HTML标签都没有(已经在view source中检查过)

I have read lots of posts which says that . can be used in query string without encoding, but I don't understand why its not working here. I think it has some issue with AngularJS.

我读过很多这样的文章。可以在没有编码的查询字符串中使用,但是我不理解为什么它在这里不起作用。我认为这和盎格鲁人有关系。

I'm using ui-router for state change and passed value to controller.

我使用ui-router来进行状态更改并将值传递给控制器。

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

1 个解决方案

#1


3  

If you are using connect-history-api-fallback on your server (like lite-server does), the URLs with a dot are not rewritten by default.

如果您在服务器上使用connect-history-api-fallback(像lite-server那样),那么带有一个点的url不会被默认重写。

connect-history-api-fallback code

connect-history-api-fallback代码

if (parsedUrl.pathname.indexOf('.') !== -1) {
  logger(
    'Not rewriting',
    req.method,
    req.url,
    'because the path includes a dot (.) character.'
  );
  return next();
}

Starting with connect-history-api-fallback version 1.2.0 the URLs with dots are allowed and you can solve this problem by using a a rewrite roule

从连接-历史-api-回退版本1.2.0开始,允许使用带点的url,您可以通过使用重写roule来解决这个问题

Example

例子

If your URL with dot is /search-result and you angular app lives in the index.html page you can add a rewrite rule to the connect-history-api-fallback like this

如果你的URL与点是/搜索结果和你的角应用生活在索引。可以向这样的连接-历史-api回退添加重写规则

rewrites: [
  {
    from: /^\/search-result/,
    to: 'index.html'
    }
  }
]

#1


3  

If you are using connect-history-api-fallback on your server (like lite-server does), the URLs with a dot are not rewritten by default.

如果您在服务器上使用connect-history-api-fallback(像lite-server那样),那么带有一个点的url不会被默认重写。

connect-history-api-fallback code

connect-history-api-fallback代码

if (parsedUrl.pathname.indexOf('.') !== -1) {
  logger(
    'Not rewriting',
    req.method,
    req.url,
    'because the path includes a dot (.) character.'
  );
  return next();
}

Starting with connect-history-api-fallback version 1.2.0 the URLs with dots are allowed and you can solve this problem by using a a rewrite roule

从连接-历史-api-回退版本1.2.0开始,允许使用带点的url,您可以通过使用重写roule来解决这个问题

Example

例子

If your URL with dot is /search-result and you angular app lives in the index.html page you can add a rewrite rule to the connect-history-api-fallback like this

如果你的URL与点是/搜索结果和你的角应用生活在索引。可以向这样的连接-历史-api回退添加重写规则

rewrites: [
  {
    from: /^\/search-result/,
    to: 'index.html'
    }
  }
]