0

我正在尝试从 url 中删除查询字符串(带有邀请令牌)而不重定向页面。

所以示例网址如下所示:

example.com/?invitation=fooo

我已经包含了 ng-router,并且我在路由中使用 hashbang(我不能在我们的项目中使用 html5 模式),但是这个查询字符串是主 url 的一部分(在 # 之前),因为我希望服务器看到它.

在常规应用程序中,我只会使用历史 API:

history.replaceState(null, null, '/');

但在使用 Angular 的应用程序中,它会导致错误:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

我不能使用 $location.path,因为 AFAIK 它只允许修改 url 的角度可路由部分,即在我的情况下 # 之后的部分。$location.search 甚至看不到它。

您知道在不重定向页面的情况下使用 Angular 从 url 中删除查询字符串的方法吗?

4

1 回答 1

1

在 Angular 中,对 URL 的所有修改都应该通过$location服务进行。$location.search您可以通过使用空对象调用方法来清除查询字符串: $location.search({})此外,请在此处查看有关如何使用该$location服务的指南

于 2014-02-04T23:13:30.003 回答