AngularJS $位置历史记录堆栈

时间:2017-02-13 15:06:11

标签: javascript angularjs ionic-framework

用户点击此链接:account/organisations/organisation1/news/21

然后我通过$location.path(url)将用户从首页(news/today)重定向到该特定页面。如果用户现在按下后退按钮,他将返回news/today,但应重定向到account/organisations/organisation1/news/

我试图拆分网址并推动各州“伪造”历史记录不起作用:

var url = "account/organisations/Vereinsplaner/news/21".split("/");
var curUrl = "";
var part;
while(part = url.shift()){
     curUrl = curUrl+"/"+part;

     $location.url(curUrl);
     $location.replace();
     $window.history.pushState(null, 'any', $location.absUrl());
 }

背景:我通过Ionic App中的PushNotification获得此链接。当用户点击它时,他将被重定向到子页面但无法返回(因为没有可用的历史记录)。

1 个答案:

答案 0 :(得分:1)

尝试在IONIC中使用$state.go()代替$ location因为它使用UI-ROUTER,因此首选方法是$ state.go()重定向并注册以前的状态......