0

The user clicks for example on this link: account/organisations/organisation1/news/21

I then redirect the user via $location.path(url) from the startpage (news/today) to that specific page. If the user now presses the back button he gets back to news/today but should be redirected to account/organisations/organisation1/news/

My attempt to split the url and push the States to 'fake' the history doesn't work:

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());
 }

Background: I get this link via PushNotification in an Ionic App. When the user clicks on it, he will be redirected to the subpage but cannot go back (because no history is available).

Mazz
  • 1,859
  • 26
  • 38
  • if you're using ionic have you tried to use $state.go() instead of $location ? – federico scamuzzi Feb 13 '17 at 15:37
  • http://stackoverflow.com/questions/14070285/how-to-implement-history-back-in-angular-js ? – Itsik Mauyhas Feb 13 '17 at 15:56
  • @federicoscamuzzi Thanks mate, it's working. I can nest the `$state.go()` with the returned promise. Exactly what i was looking for. I don't know if it is the most beautiful solution but it works ;) – Mazz Feb 13 '17 at 15:58
  • ok if it works i post as answer..i think it's best solution cause in IONIC you're using UI-ROUTER .. so $state.go is preferedd... if it hepled you and you want rate it!..thnx! – federico scamuzzi Feb 13 '17 at 15:59

1 Answers1

1

try to use $state.go() instead $location cause in IONIC it use UI-ROUTER so the preferred method is $state.go() to redirect and to register previous state ...

federico scamuzzi
  • 3,708
  • 1
  • 17
  • 24