Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

url - "dot" in query string parameter - AngularJS

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

This URL is working fine:

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

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

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

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

And nothing else, not even any HTML tags(has checked that in 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.

Any help would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 code

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

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...