Removing the fragment identifier from AngularJS urls (# symbol)

后端 未结 14 2237
Happy的楠姐
Happy的楠姐 2020-11-22 00:01

Is it possible to remove the # symbol from angular.js URLs?

I still want to be able to use the browser\'s back button, etc, when I change the view and will update th

14条回答
  •  醉梦人生
    2020-11-22 00:36

    According to the documentation. You can use:

    $locationProvider.html5Mode(true).hashPrefix('!');
    

    NB: If your browser does not support to HTML 5. Dont worry :D it have fallback to hashbang mode. So, you don't need to check with if(window.history && window.history.pushState){ ... } manually

    For example: If you click: Some URL

    In HTML5 Browser: angular will automatically redirect to example.com/other

    In Not HTML5 Browser: angular will automatically redirect to example.com/#!/other

提交回复
热议问题