ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.03k stars 13.51k forks source link

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

Closed gigablox closed 9 years ago

gigablox commented 10 years ago

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 commented 10 years ago

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

We'll fix this in a different way soon.

What's your use case?

stefan-1st commented 10 years ago

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 commented 10 years ago

Ticket #1525 may be related to this.

jjhuff commented 10 years ago

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

LukeDeighton commented 10 years ago

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 commented 10 years ago

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

kl3ryk commented 9 years ago

Mine solution:

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

$state.go('app.playlists');
jorgecasar commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 https://github.com/driftyco/ionic/issues/1287#issuecomment-63248366 or https://github.com/driftyco/ionic/issues/1287#issuecomment-67752210 (if you are using beta14)

HriBB commented 9 years ago

@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 commented 9 years ago

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.

danharper commented 9 years ago

This is still an issue.

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

mattzuba commented 9 years ago

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 commented 9 years ago

mattzuba

http://workservis.ru/binarnyj_rejting

21.03.2015, 00:58, "mattzuba" notifications@github.com: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 commented 9 years ago

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

gigablox commented 9 years ago

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 commented 9 years ago

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 notifications@github.com 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 https://github.com/driftyco/ionic/issues/1287#issuecomment-102499905.

ashconnell commented 9 years ago

I built a solution to remove states from history here: https://github.com/driftyco/ionic/issues/3750 It plays nice with cached views and swipe-back in 1.0.0

jorgecasar commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 commented 8 years ago

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

StevenConradEllis commented 8 years ago

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 commented 8 years ago

@colllin 's solution works for me.