【问题标题】:Angular Route Always need slash if it's case insensitive如果不区分大小写,Angular Route 总是需要斜线
【发布时间】:2017-10-19 20:46:22
【问题描述】:
  • 我在 IIS 上创建了名为 SA 的虚拟目录,如果键入“Localhost/SA”或“Localhost/Sa/”,一切正常,但如果我键入 URL 不区分大小写,如“Localhost/Sa”,最后没有斜杠,路由失败返回任何页面。
  • 如果我禁用了 html5mode,它会得到“404 page not found”页面。 $locationProvider.html5Mode(false);

这是我使用的解决方法:

 $urlMatcherFactory.caseInsensitive(true);
 $urlMatcherFactory.strictMode(true); // or off nothing is work 

 $urlRouterProvider.rule(function ($injector, $location) {
            var path = $location.path(), normalized = path;//.toLowerCase();
            template = path;

            if (path !== normalized) {
               $location.replace().path(normalized);
            }
           }
        });
  • 尝试通过添加 $urlRouterProvider.rule 将“/”连接到 URL 的末尾,但它也不起作用,并且无法在角引导之前将“/”连接到 URL 的末尾。

我已经解决了这个问题,请帮忙。

【问题讨论】:

    标签: javascript angularjs asp.net-mvc-5 angular-ui-router


    【解决方案1】:

    最后,我找到了解决此问题的方法,方法是在 Angular 引导之前修改 URL,在脚本标记的 _Layout.cshtml 文件中,如果请求的 URL 以根应用程序路由结尾(使用 baseSiteUrlPath 键) 并且工作正常。

       if (window.location.href.substr(-1) != '/' 
            && window.location.href.toLowerCase().endsWith(baseSiteUrlPath.toLowerCase().substr(0, baseSiteUrlPath.length - 1)))
            window.location.href += '/';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      相关资源
      最近更新 更多