Comments (8)
related: angular-ui/ui-router#3187 (comment)
Yes, I'd like to address this issue.
Note that we have to be smart about when to use/not use replace. We should only use replace if the router is responding to a browser url change. We should not use replace if the transition was initiated using $state.go()
for instance. Here is why:
router responds to URL change
url changed to /A
-> find ui-router state 'A' -> begin transition -> redirect to 'B' -> activate 'B' -> update URL with { location: 'replace' }
The URL changed to /A
due to either a href
link clicked or a sync during the initial application load (for example, user clicked a bookmark). Once we redirect to 'B', we don't want /A
in the browser history, so replace is correct.
router initiates transition via $state.go()
browser url is /Z
-> click ui-sref="A"
-> $state.go('A')
-> begin transition -> redirect to 'B' -> activate 'B' -> update URL without replace
The browser URL is only updated after a transition is successful. The url is never updated in response to the original transition to 'A'. After redirecting and activating B
, we don't want to use replace
because it would clobber the /Z
in the browser history.
necessary changes
The code for this belongs in the redirect building code. Given an existing Transition
(to 'A') that should be redirected and a new target ('B'), this code creates a new Transition
to 'B' based on the original Transition.
This new Transition's options could be set to location: 'replace'
if the original Transition's was started due to the url changing. I think checking for options().source === 'url'
on the original Transition should be correct.
from core.
Ok I think I understand what you mean now with the concern on when to use location: 'replace'
, however I'm curious, for the explanation on router initiates transition via $state.go() are you saying that's the current behavior in the version 1.x code now, or the behavior you would like to see?
The reason I ask is because by the explanation:
The browser URL is only updated after a transition is successful. The url is never updated in response to the original transition to 'A'.
I should not need to click the back button twice right now when a redirect occurs since the url would never have been updated in the browser for transition 'A'.
Your necessary changes suggestion would only apply to the first scenario router responds to URL change correct?
from core.
for the explanation on router initiates transition via $state.go() are you saying that's the current behavior in the version 1.x code now
That's the current behavior, and also how it should remain.
I should not need to click the back button twice right now when a redirect occurs since the url would never have been updated in the browser for transition 'A'.
Correct. In the case of a redirect initiated during a $state.go()
(for example, via ui-sref), the back button should work today. To see this in action, go here: http://plnkr.co/edit/qnsRwES54qgUW35wloal?p=preview Click other
then click home
-> redirects to home.foo
. Click back button and you arrive back at /other
Your necessary changes suggestion would only apply to the first scenario router responds to URL change correct?
Correct.
from core.
After looking at my code, I think I know why I don't see the expected behavior you mentioned for $state.go
, and it's that in some cases I am not using $state.go
, and rather ng-href. I am guessing because the links are activated as regular URLs, then the url is not prevented from updating for transition 'A' before redirecting to transition 'B'.
So the next question is, would you consider non ui-sref
and $state.go
router changes (eg. links with ng-href or href) a "router responds to URL change"?
from core.
In fact after thinking about it some more, I would understand if you said links with href or ng-href behaved like "router responds to URL change".
The reason being it is out of the ui router influence, this means ui router would only be aware of the changes via a URL change. Thus, it would behave like:
url changed to /A -> find ui-router state 'A' -> begin transition -> redirect to 'B' -> activate 'B' -> update URL with { location: 'replace' }
Which then leads to the suggested change you requested for the code segment.
Hope I am on the right track
from core.
would you consider non ui-sref and $state.go router changes (eg. links with ng-href or href) a "router responds to URL change"?
Yes, anything which updated the URL (including href) is processed by angular which broadcasts the $locationChangeStart
event. the ng1 adapter code listens for $locationChangeSuccess
and then tells the urlRouter to update (check each URL rule against the current URL, and invoke the callback for the matched rule). When a state is matched, its rule calls $state.go(matchedstate, matchedparams, { source: 'url' })
and informs that the state change was triggered by a url change.
from core.
Hope I am on the right track
Exactly!
from core.
closed by 23e2b78
from core.
Related Issues (20)
- License clash MIT vs CC BY-SA 3.0 HOT 2
- @uirouter/react 0.8.9 not finding UIRouter HOT 1
- Any plan for Svelte 3? HOT 7
- Can't compile angular 8 under typescript "~3.5.3" HOT 3
- Version 6.0.2 breaks using ui-router core on Node.js without a browser HOT 1
- Can't bootstrap a hybrid application in Angular 8 due to commonservices being undefined HOT 6
- string parameters are url encoding issue HOT 5
- is AOT supported? HOT 1
- Ability to set defaultHrefOpts globally HOT 3
- Ugrading to uirouter1.x and installed ui-router-core and ui-router-angularjs ,doesnt support legacy code base HOT 1
- `inherit` is documented as having the wrong default value HOT 1
- Cannot read property 'when' of undefined HOT 19
- Child states their childs, show the parent component HOT 3
- Set uiOptions.reload of [uiSref] to a future load state name lead to error at first load HOT 1
- license issue HOT 1
- How to lazy load with chunks HOT 1
- Support Ivy partial compilation HOT 10
- `ParamDeclaration.inherit = false` is ignored by `$state.href()`
- Issue with StateParams HOT 4
- error TS1086: An accessor cannot be declared in an ambient context (v6.1.1) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.