-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Controlling scroll behavior when clicking a <Link> #810
Comments
The string API is gone, you only have the two I think your problem is that the browser itself does the scrolling. With Sadly, due to browser inconsistencies and the lack of an API, I don't think there's a good way to make a robust An option could be to relocate the scrollbar using css overflow, but that could also disable some wanted browser features such as "Scroll to top". Edit: Oops, didn't notice you were talking only about Links, not back button. Ignore my post ;) |
It works within the route and its children. Applying it to leaf routes only makes transitions within each of them (e.g. param changes) ignoring scroll, but transitions between one and another of them will still reset scroll. What you want is to put // a->a, ignore scroll
// b->b, ignore scroll
// a->b or b->a, reset scroll
<Route>
<Route name='a' ignoreScrollBehavior />
<Route name='b' ignoreScrollBehavior />
</Route>
// a->a, ignore scroll
// b->b, ignore scroll
// a->b or b->a, ignore scroll
<Route ignoreScrollBehavior>
<Route name='a' />
<Route name='b' />
</Route> |
@gaearon I tried it both ways before posting. Trying it again, putting By placing it on individual routes, I thought any transition to that route would not cause a change. It would be nice to have some of that granularity as a feature (although not needed in this case). |
Any chance you're not immediately rendering the whole content? In this case page will collapse and there's no way for us to restore position afterwards. |
I'm afraid this would feel very arbitrary and too easy to misuse. It's really about “zones” in your app where scrolling doesn't switch, not individual routes. Route nesting allows us exactly that. |
@gaearon When you click a I also just put the project on GitHub so we can discuss this easier. The only thing that doesn't work in the GitHub version is that you can't directly visit a filtered url. Live Demo |
As far as I can see, this is your problem: https://github.com/MadLittleMods/react-flux-todomvc/blob/master/js/app.js#L13 Each time you switch filter, you render a different class. You can probably change it to always use run(function (Handler, state) {
var lastRoute = state.routes[state.routes.length - 1];
React.render(<Handler filter={lastRoute.name} />, document.getElementById('todoapp'));
}) |
@gaearon In reality the Looking at previous issues, etc when you could just pass props directly on the How are others solving this problem more elegantly? run(function (Handler, state) {
var filter = TodoConstants.TODO_FILTER_ALL;
var lastRoute = state.routes[state.routes.length - 1];
if(lastRoute === 'all') {
filter = TodoConstants.TODO_FILTER_ALL;
}
else if(lastRoute === 'active') {
filter = TodoConstants.TODO_FILTER_ACTIVE;
}
else if(lastRoute === 'completed') {
filter = TodoConstants.TODO_FILTER_COMPLETED;
}
React.render(<Handler filter={filter} />, document.getElementById('todoapp'));
}); My goal: I can change the filter |
The reason for removal was that, unlike React normal props, those wouldn't be kept in sync. In fact, there would be no way to update them once set. This confused many people. Why not use a param instead? Have one route, make filter a route parameter, and pass it as either a prop to Handler ( |
As you can see, you're now doing the rendering, not the router. So we can't just pass something as a prop. You need to do it yourself. |
@gaearon Params are good for lots of situations but sometimes having it directly apart of the URL instead of a GET parameter is better. For example, many sites use the same structure I am trying to implement when showing tagged content:
|
Closing since this original issue is resolved. (And turned out to be unrelated to scroll behaviors.) |
Currently the router doesn't manage scroll positions any more. Try https://github.com/taion/react-router-scroll if you stumble upon this issue while finding a solution for your scroll problem. |
I am trying to use
Route.ignoreScrollBehavior
on each route to stop the jump-to-top effect when clicking a<Link>
element. But it doesn't seem to do anything because on each page change, the scroll position moves to the top.Full snippet here
Route.ignoreScrollBehavior
Tried this from something I saw in the changelog
I tried setting the
scrollBehaviour
inRouter.create
but that doesn't seem to do anything. I also found this confusing because the documentation isn't clear on what to set the value as.I found some documentation saying you can use strings. I assume this is actually for adding the
scrollBehaviour
property to a<Route>
itself which is deprecated and removed. Strings don't work anyway because it complains about it not having aupdateScrollPosition
property.I assume that it wants to use the modules/behaviors that are exported. In the tests, the behaviours are used.
Related to issue #432.
The text was updated successfully, but these errors were encountered: