-
Notifications
You must be signed in to change notification settings - Fork 29
Conversation
CLA is valid! |
I think there should be a test to verify in https://github.com/yahoo/flux-router-component/blob/master/tests/unit/lib/RouterMixin-test.js |
@tbo Thanks for your contribution! I like it, and am thinking it could actually be applied to both replace state and push state. Like in your product size use case, your product person can also decide to use pushState instead of replaceState. What do you think about making |
@lingyan Thanks for your suggestions. I added it. But instead of encapsulating preserveScrollPosition in an option object I passed it directly. I hope that is okay. |
@tbo Thanks for updating it! Passing the params as props is totally what I wanted :) Could you add the params to the NavLink doc? Also, can we do the same for switch (navType) {
case TYPE_CLICK:
case TYPE_DEFAULT:
historyState = {params: (nav.params || {})};
if(this._enableScroll) {
if (!nav.preserveScrollPosition) {
resetScrollPosition();
} else {
historyState.scroll = {x: window.scrollX, y: window.scrollY};
}
}
pageTitle = nav.params && nav.params.pageTitle || null;
if (nav.replaceState) {
this._history.replaceState(historyState, pageTitle, newState.route.url);
} else {
this._history.pushState(historyState, pageTitle, newState.route.url);
}
break;
case TYPE_POPSTATE:
... |
@lingyan I removed the repeated code, but I opted to keep the additional nav type. What do you think about it? I also added your suggestions regarding NavLink. |
@tbo Thanks a lot for the update. My two cents: I actually think it would be better (and easier to read) to just make some minor change to the previous commit, like this: switch (navType) {
case TYPE_CLICK:
case TYPE_DEFAULT:
case TYPE_REPLACESTATE:
historyState = {params: (nav.params || {})};
if(this._enableScroll) {
if (!nav.preserveScrollPosition) {
resetScrollPosition();
} else {
historyState.scroll = {x: window.scrollX, y: window.scrollY};
}
}
pageTitle = nav.params && nav.params.pageTitle || null;
if ((navType === TYPE_REPLACESTATE) || nav.replaceState) {
this._history.replaceState(historyState, pageTitle, newState.route.url);
} else {
this._history.pushState(historyState, pageTitle, newState.route.url);
}
break;
case TYPE_POPSTATE:
if (this._enableScroll) {
... WDYT? |
@lingyan Done. |
🚢 Thanks @tbo! There is a minor tweak to move the resetScrollPosition function out for performance best practice. I will fix it after merging. |
In some use cases it is useful to change the url without reseting the scroll position. It solves #82.