Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gigablox opened this issue May 6, 2014 · 28 comments
Closed

Comments

@gigablox
Copy link

gigablox commented May 6, 2014

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.

@ajoslin
Copy link
Contributor

ajoslin commented May 9, 2014

For now: don't use location: 'replace'.

We'll fix this in a different way soon.

What's your use case?

@stefan-1st
Copy link

Are there news on this issue? I tried to use the replace option as well but hat no chance since it does not work correctly in the ionic context.

Thx
Stefan

@perrygovier
Copy link
Contributor

Ticket #1525 may be related to this.

@jjhuff
Copy link

jjhuff commented Jul 31, 2014

I've run into this when requiring login on a particular route.

@LukeDeighton
Copy link

I also have this problem, I have an initial page A that is only temporary and I want to remove it from the history so when the user presses the back button it doesn't return to that page. Is there an alternative solution in the meantime?

Edit: I use $ionicViewService.clearHistory() in the HomeController to fix the problem. It wouldn't work for every use case but it's okay for mine

@okonon
Copy link

okonon commented Oct 1, 2014

You can hide back button, to prevent users from going back to page A

@kl3ryk
Copy link

kl3ryk commented Nov 8, 2014

Mine solution:

$ionicViewService.nextViewOptions({
    disableBack: true
});

$state.go('app.playlists');

@jorgecasar
Copy link

Hi, I'm in the same issue. I want to replace a state and I don't like to show the back button. @ajoslin asked for a use case. For example, I have a state for a newspaper section (/news/tech) that will show the featured news. If there are not featured news in this section I would like to redirect the user to the post list of this section (/news/tech/all). Then If the user press the back button the controller will redirect again to the post list and the user can't go back to the state before the tech section state.

Are you planing to support location replace?

@jorgecasar
Copy link

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!

@colllin
Copy link

colllin commented 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'});

@caco0516
Copy link

caco0516 commented Jan 8, 2015

Hi my problem is that i am in the Login Page when user log in succefully , i redirect to dashboard but when back button is pressed , my app redirect to login again and thats sucks , and pretty new to angular and ionic , so any help will be awesome .

@HriBB
Copy link

HriBB commented Jan 11, 2015

I use $state.go() with notify: false and it breaks ionic navigation. I have angular-carousel and I want to be able to update the hash without reloading the view when slides change. I can successfully do so with

$state.go('app.location_image', {locationId: location.id, imageId: image.id},{
    notify: false
});

However, this break the ionic navigation stack. The expected behavior when using notify: false is that history stack is not changed.

I want it like this

Map > Location > Carousel slide 1 > Carousel slide 2 > Carousel slide 3 > [back] Location > [back] Map

But at the moment its something like this

Map > Location > Carousel slide 1 > Carousel slide 2 > Carousel slide 3 > [back] Location > [back] Carousel slide 2 > [back] Carousel slide 1

I also tried with

$ionicHistory.currentView($ionicHistory.backView());

$state.go('app.location_image', {locationId: location.id, imageId: image.id},{
    notify: false
});

But it breaks transitions.

I found https://gist.github.com/dabroek/e0e5ca33c55e8c78c6ca but not really sure how to use it.

@jorgecasar
Copy link

@HriBB, this gist does the same you did but for clicks events. It works adding navSilent attribute to the links that you want to do silent navigation.

The option notify:false is to avoid broadcast the events stateChangeStart and stateChangeSuccess. If you don't want to change the history stack you have to use location: 'replace'.

Take a look #1287 (comment) or #1287 (comment) (if you are using beta14)

@HriBB
Copy link

HriBB commented Jan 13, 2015

@jorgecasar thanks for clarifying things. I'm pretty new to AngularJS and Ionic, learning something new is always good :)

I've basically given up on this, because as soon as I solve one problem, a new one arises. I've tried just about every hack I could find, without luck.

I've made a short video illustrating the problem. The back transition is broken. I have no idea what's wrong and I don't have time to investigate. Maybe some Ionic guru will understand what the problem is after watching the video.

http://youtu.be/ELvCIjr6G_o

This is the my last attempt, if anyone is interested.

$scope.$watch('carousel.index', function (newIndex, oldIndex) {
  if (newIndex != oldIndex) {
    var image = $scope.location.files[newIndex];
    $ionicHistory.currentView($ionicHistory.backView());
    $state.go('app.location-images', {locationId: location.id, imageId: image.id}, {
      location: 'replace',
      notify: false
    });
  }
});

After carousel index changes, I want to replace the hashtag without reloading state and adding to ionic history stack.

@Ionitron
Copy link
Collaborator

Greetings @gigablox!

My sensors indicate that you have created an issue on our tracker that is more asking for usage help than an actual error with Ionic framework.

This Github issue tracker is used to track features, problems, and development of the framework.

If you wish to get help using the framework itself, the recommended place is the forum.

Thank you for allowing me to assist you.

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Jan 25, 2015
@danharper
Copy link

This is still an issue.

For now, the hack @jorgecasar and @colllin posted is working.

@mattzuba
Copy link

Another vote for reopening this - the assistance provided so far appear to be hacks, not usage answers.

My particular use-case - login is required to use my app, but once someone logs in, I don't want them to be able to use the hardware back button to go back to the login form (they need to select logout from menu). On successful login, I was using $state.go('home', null, {location: 'replace'}), but if I hit back, I just go back to the login page.

cc @ajoslin

@Fayozjon
Copy link

mattzuba

http://workservis.ru/binarnyj_rejting

21.03.2015, 00:58, "mattzuba" [email protected]:Another vote for reopening this - the assistance provided so far appear to be hacks, not usage answers.

My particular use-case - login is required to use my app, but once someone logs in, I don't want them to be able to use the hardware back button to go back to the login form (they need to select logout from menu). On successful login, I was using $state.go('home', null, {location: 'replace'}), but if I hit back, I just go back to the login page.

cc

—Reply to this email directly or .

@calendee
Copy link

Don't think re-opening is going to happen. Added Feature Request : #3418

@gigablox
Copy link
Author

Starting my second project a year later and I can't believe something as fundamental as keeping synced states between the native history API and the Ionic history provider aren't solid yet.

Am I doing something wrong?

A use case:

Let's say I have a state that is presented to a "first time user" by checking for a localStorage variable. This page happens to be a form for user settings. Once a user submit this form, he is redirected to the main "home" screen.

Clicking "back" would not make any sense because the user would be going back to this form he just filled out. I would expect the function that handles submit to contain something like:

$state.go('home',{},{location:'replace'});

However going back to this form in the future should also be possible so adding a blanket statement to say you can never go back would not be good either.

Having the ability to tailor the history through the $state provider is really what were looking for here.

@colllin
Copy link

colllin commented May 15, 2015

Daniel, maybe you can clear history before going 'home' in the case that
this was a first time user? You could pass in a firstTimeUser flag in the
state params.

On Fri, May 15, 2015 at 1:23 PM, Daniel Kanze [email protected]
wrote:

Starting my second project a year later and I can't believe something as
fundamental as keeping synced states between the native history API and the
Ionic history provider aren't solid yet.

Am I doing something wrong?

A use case:

Let's say I have a state that is presented to a "first time user" by
checking for a localStorage variable. This page happens to be a form for
user settings. Once a user submit this form, he is redirected to the main
"home" screen.

Clicking "back" would be not make any sense because the user would be
going back to this form he just filled out. I would expect the function
that handles submit to contain something like:

$state.go('home',{},{location:'replace'});

However going back to this form in the future should also be possible so
adding a blanket statement to say you can never go back would not be good
either.

Having the ability to tailor the history through the $state provider is
really what were looking for here.


Reply to this email directly or view it on GitHub
#1287 (comment).

@ashconnell
Copy link

I built a solution to remove states from history here: #3750
It plays nice with cached views and swipe-back in 1.0.0

@jorgecasar
Copy link

I make this example in the playground to test this behavior. Feel free to fork or play to get any better solution. I implement what we said, but second time you click on step2 it doesn't work.

http://play.ionic.io/app/07ab41dd024e

@dwilt
Copy link

dwilt commented Aug 7, 2015

I'm also having this issue as well. I'm using the slidebox and trying to update the URL every time and would like the back button to navigate to previous slides. The video that @HriBB posted is exactly what I'm experiencing and have tried what @jorgecasar and @colllin have posted but can't get a completely bug-free solution (not caring at this point that they are hacks).

@ashconnell
Copy link

@dwilt for your particular use case you could just intercept the android back button. You don't need to update the URL just change the slide

@yemaw
Copy link

yemaw commented Dec 9, 2015

I'm also having this issue as well. I need to update the url parameter without writing into history. Any workaround?

@StevenConradEllis
Copy link

I have tried every trick under the sun to prevent a view from being cached (including most of the suggestions above), but it still is being cached. Really annoying and kind of a showstopper for developing a proper flowing app.
When one has to do all kinds of workarounds to get something like this working, the option of just developing the app in native becomes more and more viable.
I know the platform is open source and developed by a bunch of very clever developers (for which I am very grateful), but this problem in the platform really needs to be addressed.

@longsangstan
Copy link

@colllin 's solution works for me.

gffuma added a commit to qandobooking/ionic-dashboard that referenced this issue Apr 15, 2016
gffuma added a commit to qandobooking/ionic-dashboard that referenced this issue Apr 15, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests