Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

(React Router) ScrollBehavior not works #4

Closed
lilee opened this issue Mar 27, 2015 · 9 comments
Closed

(React Router) ScrollBehavior not works #4

lilee opened this issue Mar 27, 2015 · 9 comments
Assignees
Labels

Comments

@lilee
Copy link

lilee commented Mar 27, 2015

render return null and then render the real component, ScrollBehavior not works

@RickWong
Copy link
Owner

Hmm right. Thanks for reporting this! Any idea how this can be fixed? Easiest way is to set a min-height on your component. But there must be a way to relay the query data for the first render.

@RickWong
Copy link
Owner

Hey @lilee I've just released version react-transmit@2.2.1 with the new getAllQueries() method. You should be able to transition to a route, injecting all the query results like this:

    onLinkClicked (event) {
        event.preventDefault();

        // Page.getAllQueries() returns a Promise with the query results.
        Page.getAllQueries({count: +1}).then((queryResults) => {
            // When the query results are in, then transition to a route passing
            // queryResults as route params.
            this.context.router.transitionTo("PageRoute", {queryResults});
        });
    },

Let me know whether this solves your issue.

@RickWong RickWong self-assigned this Mar 28, 2015
@lilee
Copy link
Author

lilee commented Mar 30, 2015

@RickWong Thanks, but it works not well with the bootstrap router handler, like the "Home" handler

@RickWong
Copy link
Owner

What do you mean by "not well"? Can you perhaps point it out in a few lines of code?

As for the bootstrap Home handler, that one does not need scroll behavior yet, right?

@lilee
Copy link
Author

lilee commented Mar 30, 2015

@RickWong goBack() to the Home page need scroll behavior

@RickWong
Copy link
Owner

@lilee You should be able to implement caching yourself by specifying the onQueryComplete() callback on the Homepage, and remembering the query results in localstorage or a flux-store. Upon going back to Homepage, you populate the Homepage using the remembered data.

<Newsfeed {...{repositoryUrl, stories, onQueryComplete}} />

@lilee
Copy link
Author

lilee commented Mar 31, 2015

Thanks, now it works well with the PageCache.

render() {
  var name = this.context.router.getCurrentPath();
  var cache = PageCache.get(name) || {};
  var props = assign({}, this.props || {}, cache, {
    onQueryComplete: this._onQueryComplete.bind(this)
  });
  return <Page {..props} />;
}
// ...

_onQueryComplete(error, result) {
 var name = this.context.router.getCurrentPath();
 if (error) {
   return;
 }
 PageCache.set(name, result);
}

@RickWong
Copy link
Owner

That's nice! Thanks for reporting back your solution.

@RickWong RickWong changed the title react-router ScrollBehavior not works (React Router) ScrollBehavior not works Apr 2, 2015
@RickWong
Copy link
Owner

RickWong commented Apr 3, 2015

@lilee Note that in react-transmit@2.5.0 I renamed onQueryComplete(error, result) to onQuery(promise) and you get a promise to work with.

https://github.com/RickWong/react-transmit/blob/master/src/example.js#L6-L10

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

No branches or pull requests

2 participants