当我渲染具有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;
其他信息: