如何在 Angular JS 中禁用哈希重定向

how to disable hash redirect in angular js

本文关键字:哈希 重定向 JS Angular      更新时间:2023-09-26

我有一个网址如下

http://www.something.com/sometest/test/#registration

一些逻辑是基于 IE 的 #registration 编写的。

现在,由于我正在使用角度js,并且它正在重定向如下,这破坏了逻辑。

http://www.something.com/sometest/test/#/registration

我想到了html5 mode但它正在创建其他问题,例如我的页面中的链接不起作用,只有网址正在更新(我猜当我们使用 html5mode 时这是预期的)。所以,我不想使用html5mode。我只是想阻止#的事情重定向到/#/.

请让我知道如何禁用此重定向

注意:我没有使用路由,也不需要它。我也不想使用html5mode。这是和现有的实现,我需要在angular js应用程序中使用它来打开弹出窗口或其他东西。

如果你的应用程序在/sales/下运行,尝试在索引中设置基本路径.html并打开 html5Mode:

<base href="/sales/index.html" />

否则

<base href="/" />
如果您使用的是IE9,则HTML5

模式将起作用,因为IE9不支持HTML5历史记录API

function supports_history_api() {
  return !!(window.history && history.pushState);
}

请参阅使用$location

这将起作用!

干杯:)

我自己解决了这个问题。这是由于向控制器注入了$location服务。

//issue
app.controller("testController", ["$scope", "$location", function($scope, $location) {
}]);

我从控制器中删除了$location服务,问题已解决。

//resolved
app.controller("testController", ["$scope", function($scope) {
}]);