Angular Hash versus Hashbang

我的梦境 提交于 2019-12-13 13:27:40

问题


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.

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.

The default route:

configRoutes.$inject = ['$urlRouterProvider'];
function configRoutes ($urlRouterProvider) {
    $urlRouterProvider.otherwise('/');
}

App #1 resolves this... http://localhost:3000 ... to this ... http://localhost:3000/#/

App #2 resolves this... http://localhost:3001 ... to this ... http://localhost:3001/#!/

Note the last two characters in the default URL.

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.

Current versions:
angular-ui-router v0.3.2
angular v1.6.0


回答1:


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("");  
});


来源:https://stackoverflow.com/questions/41286031/angular-hash-versus-hashbang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!