question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$state.go('mylocation', {}, {location:'replace'}); ignored by back button.

See original GitHub issue

Let’s say I redirects users to a different view if they arrive at a route that is out of sequence:

if($state.previous.name != 'part3'){
  $state.go('part1', {}, {location:'replace'});
}

When the user is redirected the back button in the nav bar is still there, but the history API has been updated and the previous state was effectively eliminated already.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:28 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
colllincommented, Dec 20, 2014

@jorgecasar Super hacky but it’s definitely the path of least resistance. Thanks for the tip. The new syntax after beta.14 is:

$ionicHistory.currentView($ionicHistory.backView());
$state.go('bla', ..., {location: 'replace'});
2reactions
jorgecasarcommented, Nov 17, 2014

Hi again, after some interesting reading of the ionic code, specifically the $ionicViewService I found this solution, replace the currentView with the backView, that it’s exactly location replace does:

$rootScope.$viewHistory.currentView = $rootScope.$viewHistory.backView;
$state.go('bla');

Enjoy!

Read more comments on GitHub >

github_iconTop Results From Across the Web

$state.go('mylocation', {}, {location:'replace'}); ignored ... - GitHub
Hi my problem is that i am in the Login Page when user log in succefully , i redirect to dashboard but when...
Read more >
Back button fails after window.location.replace(href)
When using window.location.href you are adding one more state so Page3 will be set to State3 and when you click the back button...
Read more >
location.replace() - Web APIs - MDN Web Docs
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the ...
Read more >
Change location settings | Android Developers
When the Task completes, your app can check the location settings by looking at the status code from the LocationSettingsResponse object. To get...
Read more >
How do you redirect to another page in Javascript? - Medium
window.location.replace('http://www.example.com') ... window.history.go(-1) ... meaning the user won't get stuck in a never-ending back-button fiasco.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found