routeProvider与$ locationProvider启用的html5Mode不匹配任何路径

时间:2015-07-14 23:28:46

标签: angularjs route-provider

我正在尝试匹配任何路径,当我没有启用HTML5Mode时它会起作用,但它会在URL中添加/#

为了摆脱/#,我启用了HTML5Mode,它会提取默认网址,但如果刷新网页则无效。

以下是我的相关代码:

myApp.config(
    function($routeProvider, $locationProvider, RestangularProvider){

    RestangularProvider.setBaseUrl('http://someLink:3000');

    $routeProvider
      .when("/:path", { 
        template: function($location){
            console.log($location.path);
            // pull data from database corresponding to $location.path
        }, 
        controller: function ($scope, $location) {
          console.log($location.$$path  + ' called');
        }
      })
      .otherwise({redirectTo: "/link1"});

      $locationProvider.html5Mode(true);    // does not work after I add this and the app is refreshed
      $locationProvider.html5Mode(true).hashPrefix('!');  // does not help either
    }
);

我该如何解决这个问题?

0 个答案:

没有答案