Skip to content
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

location 'replace' not working #1007

Closed
somentelucas opened this issue Apr 6, 2014 · 35 comments
Closed

location 'replace' not working #1007

somentelucas opened this issue Apr 6, 2014 · 35 comments
Assignees

Comments

@somentelucas
Copy link

I'm doing a transition to the same state (different params) and I intend to NOT keep this transition in history, so I did

$state.go("state.name", {param: param}, {location: 'replace'});

But when I go back it still goes through all the previous states.

@somentelucas
Copy link
Author

So, has anyone tried 'replace' and knows if that works?
Thanks

@nateabele
Copy link
Contributor

Can you post a plunkr that demonstrates the issue?

@ovidiubuligan
Copy link

I am also seeing this behavior with release v0.2.8 (2014-01-16)

@c0bra
Copy link

c0bra commented Jul 11, 2014

Seeing this in v0.2.10

@JoshWillik
Copy link

Also seeing this is v0.2.10

Edit: Also seeing this is v0.2.11

@JoshWillik
Copy link

I'm withdrawing my endorsement of this issue. Trying to replicate the issue in Plunkr revealed a bug in my code that was no fault of ui-router.

@sergey-ivlev
Copy link

I see the same behavior.
from parent state I did
$state.go(".childState.id", $stateParams, {location: 'replace'}).
When I go back at first time, it work correctly (it return me to parent state), but if repeat this (route to child state and go back ) two or more times it goes through all states to the root state.

@christopherthielen
Copy link
Contributor

Post a plunkr or this won't be addressed.

@FreakTheMighty
Copy link

I'm seeing the same thing. I'll see if I can't put replicate in plunkr. Funny, I just create a plunkr/issue for ember for their replace functionality.

@FreakTheMighty
Copy link

Here's a plunkr http://embed.plnkr.co/1mykz3/preview.

  1. Starting on route 0
  2. Click on the tab for route 1, the route redirects to sub route routet1.list with location set to 'replace'
  3. Click the back button, it should skip route1 and return to route0

If I repeat the last two steps, the route will no longer go back to route 0.

Edit

I replaced $state.go with $state.transitionTo and it reliably breaks for me after navigating to route1 twice.

@FreakTheMighty
Copy link

Ping, are people able to see the issue with this plunkr?

@mrtho1
Copy link

mrtho1 commented Oct 30, 2014

I wasn't able to, but I am seeing this issue in my app. I'm using ui-router-extras future states, not sure if that has anything to do with it.

@andertun
Copy link

@FreakTheMighty I am able to see the issue in your plunkr.

@OverZealous
Copy link

In case someone else hits this: I discovered it was being caused by angular-permission for me. Due to the way it's designed, it actually intercepts every state change, and breaks any options being passed to $state.go or $state.transitionTo.

(Also: note that permissions is inherited, so to see that removing permissions fixes the issue, you may need to set data.permissions to false.)

@OverZealous
Copy link

As a follow up, I really don't see a practical solution to this issue unless ui-router passes options into the $stateChangeStart event (and others).

I think the event broadcasts should be updated to toState, toParams, fromState, fromParams, options, which will allow a transition even to be paused, inspected or modified, then refired exactly as it was originally if appropriate.

@danharper
Copy link

For anyone using Ionic, there's a separate issue with their Back button. There's a couple of quite hacks in this issue:

ionic-team/ionic-framework#1287

@astanb
Copy link

astanb commented Jun 22, 2015

I agree with @OverZealous, there really needs to be a way to access the options passed to ui-sref-opts, I am currently stuck as I need to interrupt a state change and then continue later on, but there is no way for me to find out whether I passed any options with the state change.

@christopherthielen
Copy link
Contributor

I'll accept a PR that adds options as param #5 to state events

@mkoczorowski
Copy link

@OverZealous Thanks!
adding data.permissions: false worked for me

@petetaxi-test
Copy link

I was getting the same error as @FreakTheMighty plunkr.

Found a simple, albeit hacky workaround - put a slight delay on the $state.go using $timeout e.g. 10ms so that it happens after the first state transition completes.

@nateabele
Copy link
Contributor

options has been added to $stateChangeStart. Can we close this?

@stecd
Copy link

stecd commented Nov 10, 2015

@nateabele and how do you solve this issue using options from $statechangeStart? And where can I find the documentation for that?

@johncant
Copy link

johncant commented Dec 3, 2015

Sorry for adding noise, but $state.go("state.name", {param: param}, {location: 'replace'}); is replacing the current state with the new state for me, which is what I expected, so the back button then goes from the new state to the previous state, skipping the current state. Recommend closing, since there's been no plunkr/jsfiddle in over 18 months, and two people have eliminated angular-ui-router as the cause of their manifestation of this issue. :)

@Mirodil
Copy link

Mirodil commented Feb 12, 2016

still not wokring +1

1 similar comment
@keshavwork
Copy link

still not wokring +1

@doorty
Copy link

doorty commented Aug 11, 2016

still not working ++

@fijimunkii
Copy link

$state.go('place.to.be', $stateParams, { location: 'replace' }) is working for me.

I think the issue most people run into here is passing { location: 'replace' } as the second argument instead of the third.

@abachuk
Copy link

abachuk commented Aug 26, 2016

still not working +++

@christopherthielen
Copy link
Contributor

christopherthielen commented Aug 26, 2016

@keshavwork

still not wokring +1

@doorty

still not working ++

@abachuk

still not working +++

These comments are not helpful. Post a plunker demonstrating that it's not working. http://bit.ly/UIR-Plunk

As far as I can tell, {location: 'replace'} works like it's supposed to. Prove me wrong by posting a reproduction.

@inad9300
Copy link

inad9300 commented Dec 6, 2016

Still not working ++++

I appreciate the effort you put on developing this open source tool, but please, if many people say this feature does not work, at least take the time to verify it properly, otherwise who is going to rely on it?

I modified your plunkr to show the case when it doesn't work: when you programmatically call go() with {location: 'replace'}, which I think is the most common use case (as oppose to embed the options on the HTML).

There you can see how states are pushed into the history despite the "replace" intention, and you can still go back to them: https://plnkr.co/edit/i3R8jaRS6TrMz3KKHT10?p=preview

@dkordik
Copy link

dkordik commented Dec 8, 2016

@inad9300 here's an updated plnkr with the state.go pieces split out from the template, and using { location: 'replace' } instead of replace: true.

Seems to work for both the buttons and the select box examples.
https://plnkr.co/edit/H5FWyXlEjjLlHtC1ZqHP?p=preview [edit: woops, had your link at first]

@inad9300
Copy link

My mistake, sorry. So apparently it works after all :) Thanks for taking the time!

@christopherthielen
Copy link
Contributor

christopherthielen commented Dec 15, 2016

@inad9300 next time please be considerate of the amount of time OSS maintainers spend. Snarky comments like "Still not working ++++" make me reconsider my involvement in OSS.

"if many people say this feature does not work, at least take the time to verify it properly"

I couldn't reproduce the issue. I posted a WORKING EXAMPLE. Issues without reproductions are very frustrating. I appreciated that you posted the plunker though 👍

@emanuel-virca
Copy link

I had the same issue and after research i have realized i was wrongly understanding the concept of replace.
When using location.replace you are replacing (exclude from history) the current page (not the one navigating to) with the page you are navigation to. So in ui-router case, when using $state.go('place.to.be', $stateParams, { location: 'replace' }) it will actually replace the current state with the state 'place.to.be'.
In other words, if you want to navigate to a page R that just redirects to another page X make sure you are navigation from page R () by using $state.go('X', $stateParams, { location: 'replace' }) . This way R will be replaced with page X

@juliobguedes
Copy link

juliobguedes commented Jul 17, 2018

Has this problem been solved? I'm using ui-router v0.2.13 along another group of dependencies (which I unfortunately cannot post here) and I'm facing the problem 😢

What I have here is: I have a list of objects, and clicking in an object on the list redirects me to an intermediary screen with a state.go(). In this intermediary screen, I use location: 'replace' to replace with the final screen after some logic.

When I click the navigator button once it works and I go to the previous screen, but clicking twice keeps me on the previous screen after a redirecting...

My exact code is $state.go(finalScreen, finalParams, { location: 'replace' });

PS: Sorry for my bad english, it isn't my home language, and I'm not used to technical terms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests