Angular Hash 与 Hashbang [英] Angular Hash versus Hashbang
问题描述
为什么 Angular 有时在 URL 中使用散列,而有时使用散列?我已经开始从头开始编写两个 Angular 应用程序.两者都没有使用 HTML5 模式.两者都有相同的默认路由.但是,默认网址的显示方式有所不同.
Why does Angular sometimes use a hash in the URL and other times use a hashbang? I've started writing two Angular apps from scratch. Neither are using HTML5 mode. Both have the same default route. However, the default URLs display differently.
我已经看到这种随机行为至少一年了……早在 angular-route v1.6 之前.另外,我一直使用 angular-ui-router.
I've been seeing this random behaviour for at least a year... long before angular-route v1.6. Also, I've always used angular-ui-router.
默认路由:
configRoutes.$inject = ['$urlRouterProvider'];
function configRoutes ($urlRouterProvider) {
$urlRouterProvider.otherwise('/');
}
App #1 解决了这个问题...http://localhost:3000……对这个……http://localhost:3000/#/
App #1 resolves this... http://localhost:3000 ... to this ... http://localhost:3000/#/
App #2 解决了这个问题...http://localhost:3001……对这个……http://localhost:3001/#!/
App #2 resolves this... http://localhost:3001 ... to this ... http://localhost:3001/#!/
注意默认 URL 中的最后两个字符.
Note the last two characters in the default URL.
我知道如何激活 HTML5 模式和漂亮的 URL.这不是我要问的.我真的很想了解上面两个 URL 的重要性以及为什么 Angular 以不同的方式编写它们.
I know how to activate HTML5 mode and pretty URLs. That is not what I'm asking. I would really like to understand the significance of both URLs above and why Angular is writing them differently.
当前版本:
angular-ui-router v0.3.2
角度 v1.6.0
Current versions:
angular-ui-router v0.3.2
angular v1.6.0
推荐答案
当我们从 angular 1.5 升级到 angular 1.6 时,我们应用的 URL 从 /#/
变成了 /#!/
.我们通过在应用程序配置中配置 hashPrefix 解决了这个问题:
When we upgraded from angular 1.5 to angular 1.6, the URL of our app changed from /#/
to /#!/
. We fixed the problem by configuring the hashPrefix in the application config:
angular.module("myApp").config(function($locationProvider) {
$locationProvider.hashPrefix("");
});
这篇关于Angular Hash 与 Hashbang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!