服务器端渲染(节点)无法识别反应

时间:2018-12-26 18:08:56

标签: reactjs

我正在尝试将反应代码从节点服务器发送到前端以进行渲染,但是后端无法识别反应代码。这是后端代码:

// imports
var Express = require('express');
var bodyParser = require('body-parser');
var admin = require("firebase-admin");
var renderToString = require("react-dom/server");
var AppComponent = require('./AppComponent.js');
var React = require('react');
var renderToString = require('react-dom/server');
var app = Express();

// init db
admin.initializeApp();

// db ref
var root = admin.database.ref();

// Here is the function in question
app.get('/', (req, res)  => {

        var uid = req.body.uid;
        var firebase_ref = root;
        // Error occurs below at the opening <
        const appString = (render(h(<AppComponent uid={uid} firebase={firebase_ref} />)));

        res.send(appString);
})



app.listen(port, () => console.log('Server running on port '+ port + '!\n'))

控制台中的错误消息:

const appString = (render(h(<AppComponent uid={uid} firebase={firebase_ref} />)));
                                      ^

SyntaxError: Unexpected token <

0 个答案:

没有答案