AngularJS routing without the hash '#'

前端 未结 10 985
野性不改
野性不改 2020-11-22 01:40

I\'m learning AngularJS and there\'s one thing that really annoys me.

I use $routeProvider to declare routing rules for my application:

         


        
10条回答
  •  耶瑟儿~
    2020-11-22 02:06

    In fact you need the # (hashtag) for non HTML5 browsers.

    Otherwise they will just do an HTTP call to the server at the mentioned href. The # is an old browser shortcircuit which doesn't fire the request, which allows many js frameworks to build their own clientside rerouting on top of that.

    You can use $locationProvider.html5Mode(true) to tell angular to use HTML5 strategy if available.

    Here the list of browser that support HTML5 strategy: http://caniuse.com/#feat=history

提交回复
热议问题