角哈希与哈希邦 [英] Angular Hash versus Hashbang
问题描述
为什么Angular有时在URL中使用哈希,而有时却使用hashbang?我已经开始从头开始编写两个Angular应用。都不使用HTML5模式。两者具有相同的默认路由。但是,默认的URL显示方式有所不同。
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('/');
}
应用程序1解决了此问题...
http:// localhost:3000
...对此...
http:// localhost:3000 /#/
App #1 resolves this... http://localhost:3000 ... to this ... http://localhost:3000/#/
应用程序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
推荐答案
当我们从Angle 1.5升级到Angle 1.6时,我们应用的网址已从 /#/
更改为 /#!/
。我们通过在应用程序配置中配置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("");
});
这篇关于角哈希与哈希邦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!