loadInitialProps(this.props.routes, pathname, { history: this.props.history, }) .then(({ data }) => { this.prefetcherCache = { ...this.prefetcherCache, [pathname]: data, }; }) .catch((e) => console.log(e));
// only runs clizzient UNSAFE_componentWillReceiveProps(nextProps) { const navigated = nextProps.location !== this.props.location; if (navigated) { window.scrollTo(0, 0); // save the location so we can render the old screen this.setState({ previousLocation: this.props.location, data: undefined, // unless you want to keep it }); const { data, match, routes, history, location, ...rest } = nextProps; loadInitialProps(this.props.routes, nextProps.location.pathname, { location: nextProps.location, history: nextProps.history, ...rest, }) .then(({ data }) => { this.setState({ previousLocation: null, data }); }) .catch((e) => { // @todo we should more cleverly handle errors??? console.log(e); }); } }