Last active
February 17, 2016 02:32
-
-
Save timdorr/dd4c622633d589a2c0f7 to your computer and use it in GitHub Desktop.
A common pitfall I'm seeing with server-side rendering in React Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function (req, res) { | |
const history = createMemoryHistory() // <- No arg creates a history with the default first location: '/' | |
// Do some stuff with history | |
match({ history, routes, location: req.url }, (error, redirectLocation, renderProps) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function (req, res) { | |
const history = createMemoryHistory(req.path) // <- Provide the request path! | |
// This ensures the history instance is consistent during the match call below | |
// Do some stuff with history | |
match({ history, routes, location: req.url }, (error, redirectLocation, renderProps) => { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment