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).

4
  • if you're using ionic have you tried to use $state.go() instead of $location ? Commented Feb 13, 2017 at 15:37
  • stackoverflow.com/questions/14070285/… ? Commented Feb 13, 2017 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 ;) Commented Feb 13, 2017 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! Commented Feb 13, 2017 at 15:59

1 Answer 1

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 ...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.