Express引擎无法从react-router v4渲染路由

时间:2017-10-02 08:51:11

标签: javascript node.js reactjs express react-router

当我渲染具有Router标记的文件时,express jsx引擎在浏览器上只显示一个空白的html页面。有人可以指导或指出我做错了什么吗? 相关服务器设置的一部分:

const express = require("express");
const reactEngine = require('express-react-views');

let app = express();

app.set('views', path.join(__dirname, "../views"));
app.set('view engine', 'jsx');
app.engine('jsx', reactEngine.createEngine());

app.use("/testing", function (req, res) {
        res.render("index.jsx");
});

module.exports = app;

还有index.jsx:

const React = require('react');
const ReactRouter = require('react-router');
const createHistory = require('history').createMemoryHistory;
const Router = ReactRouter.Router;
const routes = require('./routes');
const injectTapEventPlugin = require('react-tap-event-plugin');

const historyRoute = createHistory();

injectTapEventPlugin();

class Index extends React.Component {
    render(){
        return(
            <Router routes={routes} history={historyRoute}/>
        );
    }
}

module.exports = Index;

所需的路线文件也是这样的:

const React = require('react');
const ReactRouter = require('react-router');
const Route = ReactRouter.Route;
const IndexRoute = ReactRouter.IndexRoute;

const App = require('./containers/App');
const FormPage = require('./containers/FormPage');
const Dashboard = require('./containers/DashboardPage');

const Routes = props => {
  return (
      <Route path="/" component={App}>
        <IndexRoute component={Dashboard}/>
        <Route path="dashboard" component={Dashboard}/>
        <Route path="form" component={FormPage}/>
      </Route>
  );
};

module.exports = Routes;

其他信息:

  • 反应版本:15.6.1
  • react-router version:4.2.0
  • 快递版:4.15.4
  • 节点版本:6.11.3
  • express-react-views:0.10.2

0 个答案:

没有答案