如何防止控制器更改哈希中的 $location
how to prevent $location in controller changing hash
该站点是在 angularjs 中构建的,但可视化是单独编码的,而不是在 angularjs 中。
将 $location 添加到应用程序的控制器时,它会将 url 中的散列部分从
更改为
app/#hashpart
至
app/#/hashpart
有什么办法可以避免这种情况吗?可视化正在创建和解释第一个版本,当我调用 my_function(构建我的站点并调用可视化)时:
$scope.$on('$locationChangeSuccess', function(event) {
$scope.my_function(location.hash.substr(2));
});
然后浏览器永远在两个哈希版本之间切换。
在 angular js 中使用 html5mode。这将从 url 中删除 #。
您需要在服务器上进行更改,无论何时请求任何页面,始终回复 index.html,否则会遇到 404。 (为您的服务器搜索 url 重写规则)
该站点是在 angularjs 中构建的,但可视化是单独编码的,而不是在 angularjs 中。 将 $location 添加到应用程序的控制器时,它会将 url 中的散列部分从
更改为app/#hashpart
至
app/#/hashpart
有什么办法可以避免这种情况吗?可视化正在创建和解释第一个版本,当我调用 my_function(构建我的站点并调用可视化)时:
$scope.$on('$locationChangeSuccess', function(event) {
$scope.my_function(location.hash.substr(2));
});
然后浏览器永远在两个哈希版本之间切换。
在 angular js 中使用 html5mode。这将从 url 中删除 #。
您需要在服务器上进行更改,无论何时请求任何页面,始终回复 index.html,否则会遇到 404。 (为您的服务器搜索 url 重写规则)