Skip to content
This repository was archived by the owner on May 28, 2022. It is now read-only.

Fix back button functionality in AngularJS 1.6+. #10

Merged
merged 4 commits into from
May 26, 2017

Conversation

dlongley
Copy link
Member

Changes to Angular 1.6, specifically:

angular/angular.js@2b360bf

Resulted in angular detecting window.history.pushState changes.
As a result, the stackables state that is pushed when opening
a stackable was detected by angular on the next digest cycle,
resulting in angular issuing a route change event. This event
cannot be canceled using preventDefault as angular's $browser
will attempt to revert to the previous history when this happens,
thereby mangling the history. Detecting when to cancel the route
change may also be problematic as the necessary information to
determine whether it's a valid route change may not be available.

Instead, a horrible hack was written to override onUrlChange
listeners so that they will not detect any changes to history
state when a stackable is open or when all stackables have been
closed and we are reverting back to the previous history state.

This change also makes it such that links to the same route that
a stackable was opened from cannot be used in the stackable, but
this is generally considered an anti-pattern, defeating the
purpose of using a stackable to preserve the state on the route
it was launched from. So, don't use links like that.

Changes to Angular 1.6, specifically:

angular/angular.js@2b360bf

Resulted in angular detecting `window.history.pushState` changes.
As a result, the stackables state that is pushed when opening
a stackable was detected by angular on the next digest cycle,
resulting in angular issuing a route change event. This event
cannot be canceled using `preventDefault` as angular's `$browser`
will attempt to revert to the previous history when this happens,
thereby mangling the history. Detecting when to cancel the route
change may also be problematic as the necessary information to
determine whether it's a valid route change may not be available.

Instead, a horrible hack was written to override `onUrlChange`
listeners so that they will not detect any changes to history
state when a stackable is open or when all stackables have been
closed and we are reverting back to the previous history state.

This change also makes it such that links to the same route that
a stackable was opened from cannot be used in the stackable, but
this is generally considered an anti-pattern, defeating the
purpose of using a stackable to preserve the state on the route
it was launched from. So, don't use links like that.
@mattcollier mattcollier merged commit 97de33d into master May 26, 2017
@mattcollier mattcollier deleted the fix-angular-1.6-history branch May 26, 2017 22:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants