Andrei Duca
Aug 31, 2018 · 1 min read

You basically have to add both:

// root (/) should always serve our server rendered page
router.use('^/$', actionIndex);
// other static resources should just be served as they are
router.use(express.static(
path.resolve(__dirname, '..', '..', 'build'),
{ maxAge: '30d' },
));
// any other route should be handled by react-router
router.use('*', actionIndex);

Order is important as the router will stop at first match.

    Andrei Duca

    Written by

    Frontend Engineer | creator of Snipit.io

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade