React JS:从服务器渲染迁移到纯客户端

我有反应的项目,这是以前使用节点js服务器设置,并利用客户端和服务器端渲染和路由。 我需要移动它,以便它使用纯粹的客户端渲染/路由。 我该如何去做呢?

server.js文件如下所示:

var Router = require('react-router').Router; var routes = require('./public/js/' + defaultAppName + '/' + defaultAppName + '.node.js'); app.get('*', function (req, res, next) { var location = new Location(req.path, req.query); try { Router.run(routes(), location, function (e, i, t) { var str = ReactDOMServer.renderToString( React.createElement(Router, i)); }); } catch (e) { console.error(e); return next(); } }); 

目录结构看起来像 –

 |- server.js |- gulpfile.js |- public |- js |- app.node.js |- src |-jsx | |-app | | |-actions | | |-components | | |-reducers | | |-routes | | |-index.html |-sass | |-app | | |-main 

从服务器端代码中删除路由,并为您的应用程序的index.html提供任何URL,并让路由由您的应用程序入口点处理。 例如

 var static_path = path.join(__dirname, 'public'); app.use(express.static(static_path)); app.get('/', function (req, res) { res.sendFile('index.html', { root: static_path }); }); 

在应用程序的入口点,例如app.jsx

 var ReactDom = require('react-dom'); var Routes = require('/path/to/routes'); ReactDom.render(Routes, document.querySelector('.any-place-on-dom'));