React Router v4 ReactDOMServer.renderToString not working

Hello everyone. I am very new to this community.
I found this site by searching ways to solve problems that i have
about React Router v4 and ReactDOMServer.renderToString function.

I am trying to make my react project working in server side,
and found a web site explaining how to implement it.

To go further explanation of my code, let me show you my codes…

app.get('/*', (req, res) => {
    const context = {}
    const app = renderToString(
        <Provider store={createStoreWithMiddleware(reducers)}>
            <StaticRouter location={req.url} context={context}>
                <Route exact path='/' component={Home}></Route>

                <Route path='/home' component={NaviBar}></Route>


                <Route exact path='/login' component={Login}></Route>
                <Route exact path='/register' component={Register}></Route>

    const indexFile = path.resolve('../index.html')
    fs.readFile(indexFile, 'utf8', (err, data) => {
        if(err) {
            console.error('Something wend wrong : ', err)
            return res.status(500).send('Opps, better luck next time!')
        return res.send(
            data.replace('<div id="container"></div>', `<div id="container">${app}</div>`)


As it is showen in the git bash error message, renderToString() function seems to have an issue with its element.
" Unexpected token < "

Can anybody help me solving this issue… or give me any kinds of hints to solve this…?

Thank you!

Looks like a parsing issue.

or this:

May help.

Thanks for the help! I will try to read through the link you showed me! :+1: