当路径以“.”开头时,$urlRouterProvider.otherwise('/') 不起作用

$urlRouterProvider.otherwise('/') doesn't work when the path starts with '.'

我的 Angular 应用程序(v1.5.3,ui-router v0.3.2)中有以下内容:

/app/router.js

function router ($locationProvider, $urlRouterProvider) {
  $locationProvider.html5Mode(true);
  $urlRouterProvider.otherwise('/');
}

angular
  .module('analytics')
  .config(router);

通常这会按预期工作。我没有到 /nonsense 的路由,所以对 /nonsense 的请求被路由到 /。但是,如果我尝试导航到 /.nonsense,我会得到 40 倍的响应(在 Chrome 和 curl 中为 404;在 Firefox 和 Safari 中为 403;未测试 IE 或 Edge)。

但是对 /#/.nonsense 的请求被正确地重新路由到 /

初步问题:这是 expected/desired 行为吗?

主要问题:如果这不是我的行为 expect/desire,我可以尝试什么解决方法?

更新#1

有人认为这不是 Angular 问题,而是服务器配置问题。

我是 运行 使用 gulp (v4.0.0) + 浏览器同步 (v2.12.5) 的本地应用程序。在产品中,我们使用的是 nginx。该问题在两种环境中都是一致的。

浏览器同步配置代码为:

/gulp-config/serve.js

const browserSyncInit = (baseDir, routes) => {
  sync.init({
    startPath: '/',
    server: {
      baseDir: baseDir,
      routes: routes
    },
    browser: 'default',
    notify: false,
    // The variable C is a config object defined elsewhere 
    host: C.siteConfig.webHost,
    port: C.siteConfig.webPort,
    https: C.siteConfig.webProtocol === 'https',
    open: 'external'
  });
}
...
browserSyncInit(
  [C.tmp(), C.app()],
  {'/bower_components': 'bower_components'}
);

因此,如果确实是服务器配置问题,我可能可以修改传入的路由对象,即:

routes['/**/.*'] = '' 更新#2:这实际上不起作用:(

但我不确定如何在 nginx 中完成这类事情,因为我没有参与项目的部署并且从未使用过 nginx。

我假设nginx中有一个使用通配符或正则表达式拦截路由的配置过程?

更新#3

这是网站 Angular 应用程序部分的 nginx 配置。

/etc/nginx/slave/sites-available/example-dev_proxy.conf

upstream example-dev {
  zone upstream_dynamic 128k;
  server example-dev.service.internal.consul:31238 resolve;
}

server {
  listen 443 ssl;
  server_name *.dev.example.com;
  server_tokens off;
  add_header X-Frame-Options SAMEORIGIN;
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
  ssl_dhparam /etc/nginx/slave/ssl/dhparam.pem;

  location / {   
    proxy_pass https://example-dev;
    proxy_redirect off;
    proxy_set_header Host ;
    proxy_set_header X-Forwarded-For ;
    proxy_set_header X-Real-IP ;
    proxy_set_header X-Forwarded-Proto ;
  }

  ssl_certificate /etc/nginx/slave/ssl/example_dev_proxy.crt;
  ssl_certificate_key /etc/nginx/slave/ssl/example_dev_proxy.key;
  ssl_verify_client off;
  ssl_session_timeout 5m;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS;
  ssl_prefer_server_ciphers on;
}

所以这似乎是一个 nginx 问题,而不是 Angular 问题。对于以点开头的任何路径,默认行为是 return 403。但据我了解,这是一种将默认行为覆盖为 return 404 的方法:

location ~ /\. { deny all }

有关此内容的更多信息here. And for nginx n00bs like myself, I found this 有助于理解上述行。