cereallarceny / cra-ssr

[DEPRECATED] Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk
484 stars 118 forks source link

force trip to the server on each page #39

Closed jtorjo closed 5 years ago

jtorjo commented 6 years ago

Some of my pages need to be always executed on the server side. Initially I thought this was the case, but a lot of the requests are handled on the client side.

I'm using your template, I modified it a bit. Having said that, I thought that dispatch(push (new_url)) would force a trip to the server:

export const renewLicense = () => dispatch =>
    new Promise(resolve => {
        var t = RENEW_LICENSE;
        dispatch({
            type: t,
        });
        dispatch(push( some_new_url ));
        resolve({});
    });

Do I need to change the router? I know I'm using this in loader.js: import { StaticRouter } from 'react-router';

Would changing that make any difference, or do I need to do something inside express() ?

cereallarceny commented 5 years ago

Hey @jtorjo - sorry for the (very) late reply. Pushing a new URL onto your router will not call the server. If you want to call the server, you need to reload the page. Server-side rendering works like this:

  1. The initial call to the page is made and rendered via the server
  2. All subsequent actions on the rendered page are client-side actions and doesn't involve the server

Hope that helps!