How can I get rid of the hash tag in my AngularJS site URL?

北城以北 提交于 2019-12-11 07:46:25

问题


I uploaded an AngularJS site to my gh-pages branch and pointed the DNS A records to 204.232.175.78. Now the site is live but I see a hash tag as part of the URL structure. Here are the two URLs one can see the home page of the site at

http://www.maxmythic.com/#/

http://siddhion.github.io/maxmythic_angular/#/

The URL I want visitors to enter and see in the address bar is simple maxmythic.com. If one enters maxmythic.com it redirects to http://www.maxmythic.com/#/.

How would I make the URL of the home page just maxmythic.com with out the www. and trailing /#/


回答1:


In the app's main module's config function, use the html5mode() function of the $locationProvider. Read these docs for more info: http://docs.angularjs.org/api/ng.$locationProvider and http://docs.angularjs.org/guide/dev_guide.services.$location.

Example:

angular.module('myApp', []).
  config(function($locationProvider) {
    $locationProvider.html5Mode(true);
  });


来源:https://stackoverflow.com/questions/17893292/how-can-i-get-rid-of-the-hash-tag-in-my-angularjs-site-url

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