2016-02-26 249 views
1

這是我設置了快遞路由器:服務器端渲染與痛飲模板,反應,快速

var r = require('rethinkdb'); 
var quotes = require('../model/quotes'); 
var user = require('../model/users'); 
var auth = require('../lib/auth'); 
var React=require('react'); 
var ReactDOMServer=require('react-dom/server') 
var Homepage=React.createFactory(require('../component/index.js').Homepage); 

module.exports = function(app, passport) { 

    app.get('/', function(req, res) { 
     if (req.user) { 
      res.redirect('/dashboard'); 
     } else { 
      var HomepageHTML=ReactDOMServer.renderToString(Homepage({})); 
      res.render('index',{homepage:HomepageHTML}); 
     } 
    }); 

} 

index.html看來,寫在痛飲模板引擎:

{% extends 'main.html' %} 

{% block title %}Homepage{% endblock %} 

{% block body %} 
    {{homepage}} 
{% endblock %} 

它呈現帶有標籤的字符串,而不是我用React創建的組件,現在應該如何讓Swig渲染我寫的組件?

回答

0

你試過{{ homepage.toString() }}?我認爲這將解決問題。