-
Notifications
You must be signed in to change notification settings - Fork 56
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
Enable backbutton for same routes #14
Conversation
I believe that Ember's HistoryLocation should be adding a unique id for each history state by default. I'm going to make a PR to Ember to enable this. If/when that gets pulled into a future version of Ember this addon can drop the custom location. |
For reference: emberjs/ember.js#14011 |
I added a service. The reason is to deal with multiple app instances. With the |
This looks solid, @bcardarella! We'll review internally and merge later on today. Thank you 🙏 |
Awesome. I'm looking to add some unit tests, however unit testing against |
@bcardarella Thanks for your work on this. I'm trying to run it now in our application, but it doesn't seem to be hitting the router-scroll extension of I validated that when running in chrome, the I've added locationType: "router-scroll" to In the meantime, I'm going to merge in #13 so the guides make sense for users. |
@bennycwong the guides are "correct" in that Ember only ships with four, however it uses the owner API to lookup a given location: |
Closes #12 Closes #11 * Moved mixin to root of project so the README is accurate (#11) * Added new Location object that will add unique IDs to the History API's current `state`. This allows for the scroll position to be preserved across multiple instances of the same route in the history. (#12) * Added a service to store the scroll information * Doesn't rely on jQuery This change is breaking the previous API as it now requires that the Location object be added to `config/environment.js`. To enable this: ```js // config/environment.js locationType: 'router-scroll' ```
So, @bcardarella, it should look like this inside folks' apps? // app/locations/router-scroll.js
export { default } from 'ember-router-scroll/locations/location.js'; A la ember-cli-sentry |
@briangonzalez no, this PR already should add the location to the app path. There is a I have this branch running on dockyard.com without issue. I could probably do a screen hero or a hangout in about 45 minutes if that would be helpful |
Just updated with a rabase against |
@bcardarella Ah! I see where I went wrong. I needed to update the //app/router.js
Router.reopen({
location: 'router-scroll'
}); |
did you have it explicitly set to a value? It should be pulling from your config by default: https://github.com/ember-cli/ember-cli/blob/master/blueprints/app/files/app/router.js#L5 |
@bcardarella It turns we originally had Router.reopen force 'history', which is why I had to override it in the above comment. This looks good. We can merge it in. We really appreciate your help here. Keep a lookout for us at ElixirConf this year. |
Looks like at some point during the rebase, the import Ember from 'ember';
const {
get,
inject,
run: { next },
} = Ember;
export default Ember.Mixin.create({
service: inject.service('router-scroll'),
willTransition(...args) {
this._super(...args);
get(this, 'service').update();
},
didTransition(transitions, ...args) {
this._super(transitions, ...args);
next(() => {
let scrollPosition = get(this, 'service.position');
let preserveScrollPosition = transitions[transitions.length - 1]
.handler.controller.get('preserveScrollPosition');
if (!preserveScrollPosition) {
window.scrollTo(scrollPosition.x, scrollPosition.y);
}
});
}
}); I'll go a head and clean this up. |
👍 I see that you tagged v0.0.5 but it hasn't been pushed to npm? |
Done. |
awesome :) |
Closes #12
Closes #11
API's current
state
. This allows for the scroll position to bepreserved across multiple instances of the same route in the history.
(Scroll position for historical pages #12)
This change is breaking the previous API as it now requires that the
Location object be added to
config/environment.js
. To enable this: