Angular 路线如果不区分大小写,则始终需要斜杠
Angular Route Always need slash if it's case insensitive
- 我在 IIS 上创建了名为 SA 的虚拟目录,如果键入 "Localhost/SA" 或 "Localhost/Sa/" 一切正常,但如果我键入 URL 不区分大小写,像这样 "Localhost/Sa" 没有斜线最后路线未能return任何页面。
- 如果我禁用了 html5mode,它会出现“404 页面未找到”页面。
$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 的末尾,但它也不起作用,并且无法将“/”连接到 [= 的末尾33=] 在 angular 之前 bootstrap.
我已经解决了这个问题,请帮忙。
最后,我通过修改脚本标记中 _Layout.cshtml 文件中 Angular bootstrap 之前的 URL 找到了解决此问题的方法,方法是将尾部斜杠添加到URL 如果请求的 URL 以根应用程序路由结尾(使用 baseSiteUrlPath 键)并且它工作正常。
if (window.location.href.substr(-1) != '/'
&& window.location.href.toLowerCase().endsWith(baseSiteUrlPath.toLowerCase().substr(0, baseSiteUrlPath.length - 1)))
window.location.href += '/';
- 我在 IIS 上创建了名为 SA 的虚拟目录,如果键入 "Localhost/SA" 或 "Localhost/Sa/" 一切正常,但如果我键入 URL 不区分大小写,像这样 "Localhost/Sa" 没有斜线最后路线未能return任何页面。
- 如果我禁用了 html5mode,它会出现“404 页面未找到”页面。 $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 的末尾,但它也不起作用,并且无法将“/”连接到 [= 的末尾33=] 在 angular 之前 bootstrap.
我已经解决了这个问题,请帮忙。
最后,我通过修改脚本标记中 _Layout.cshtml 文件中 Angular bootstrap 之前的 URL 找到了解决此问题的方法,方法是将尾部斜杠添加到URL 如果请求的 URL 以根应用程序路由结尾(使用 baseSiteUrlPath 键)并且它工作正常。
if (window.location.href.substr(-1) != '/'
&& window.location.href.toLowerCase().endsWith(baseSiteUrlPath.toLowerCase().substr(0, baseSiteUrlPath.length - 1)))
window.location.href += '/';