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

Why doesn't it scroll to the top when you navigate between states #119

Open
TehShrike opened this issue Dec 28, 2017 · 1 comment
Open
Assignees
Labels

Comments

@TehShrike
Copy link
Owner

As phrased by @daytonlowell:

huh, totally annoying thing I just now noticed. If you're on state A and scroll down the page and then go to state B, you won't be taken back to the top when state B loads.

A reasonable question that needs a reasonable answer written down somewhere (I know I've answered it a couple times before in chats, so it really needs to be documented).

There are other general questions like this that I know need answers, so I'm thinking there should be a new markdown file at the root of the repo named "reasonable-questions.md" or something, and a list of questions linking to the answers in that file at the bottom of readme.md.

@TehShrike TehShrike self-assigned this Dec 28, 2017
@saibotsivad
Copy link
Collaborator

Since maybe people will search for this and wonder, here's basically what I've done in a few apps:

const shouldScrollToTop = (currentState, previousState) => {
    return currentState === 'some state names' && previousState === 'some other states'
}

const stateChangeHistory = [];

stateRouter.on('stateChangeStart', state => {
    const previousStateName = stateChangeHistory[stateChangeHistory.length - 1]
    if (shouldScrollToTop(state.name, previousStateName)) {
        window.scrollTo(0, 0)
    }
    stateChangeHistory.push(state.name)
})

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

No branches or pull requests

2 participants