diff --git a/packages/react-server-test-pages/entrypoints.js b/packages/react-server-test-pages/entrypoints.js index 438eaadff..2177c5a0d 100644 --- a/packages/react-server-test-pages/entrypoints.js +++ b/packages/react-server-test-pages/entrypoints.js @@ -29,6 +29,10 @@ module.exports = { entry: "/navigation/playground", description: "Navigation playground", }, + Forwarding: { + entry: "/navigation/forward", + description: "Test how page forwarding works with passing data down", + }, StylePromises: { entry: "/styles/promises", description: "Stylesheets returned from promises", diff --git a/packages/react-server-test-pages/pages/navigation/forward.js b/packages/react-server-test-pages/pages/navigation/forward.js new file mode 100644 index 000000000..a839f867c --- /dev/null +++ b/packages/react-server-test-pages/pages/navigation/forward.js @@ -0,0 +1,38 @@ +import {ReactServerAgent} from "react-server"; + +export default class ForwardPage { + handleRoute() { + const request = this.getRequest(); + let params = request.getQuery(); + if (params) { + params = params.value; + } else { + params = 0; + } + + //fetch some data + this.data = ReactServerAgent.get('/data/delay?ms=1000&val='+params); + + return this.data.then((res) => { + //then depending on said data, forward to one of two pages, and pass along the data we pre-fetched + const pageName = (res.body % 2 === 0) ? "./forwardEven" : "./forwardOdd"; + // TODO: change this to use isBrowser when that check is available. + if (typeof window !== 'undefined') { + return require.ensure([pageName], () => { + return { + page: require(pageName).default, + }; + }); + } else { + return { + page: require(pageName).default, + }; + } + }); + } + + getElements() { + return