我刚开始使用react-create-app进行反应。我做了一个小应用,我知道我在将网站分成不同部分时遇到了麻烦。
我在做一个html5游戏的网站。我用react做了一个应用程序的快速原型(玩家可以看到其他连接的玩家,开始游戏等)。例如,为了连接玩家,我只需使用axios从JAVA spring服务器获取数据。
但是假设我想在这个应用程序之前创建一个欢迎/登录页面。Like this这个页面就是“看看这个很酷的游戏,现在就注册吧!”
我该如何使用react来做这件事呢?我应该使用React Router吗?也许稍后我想添加一个DevBlog?也许是论坛?我不想让想看devblog的人从论坛上下载所有的资源。
如何轻松缩放我的小应用程序?
我迷失了自我,似乎有很多种方法!创建parallels节点服务器?使用服务器端渲染?NextsJS?Redux?路由器?
对于一个单独工作的人来说,最好的选择是什么?
发布于 2017-03-16 22:29:11
您可以使用react-router和一种称为异步路由的东西。通过使用require.ensure,您可以使用Webpack为每条路由创建多个拆分点。
不是只有一个巨大的js/css文件,而是在用户进入特定路径时异步下载多个(想下载多少个)文件。
import { injectReducer } from '../../store/reducers'
export default (store) => ({
path : 'forum',
/* Async getComponent is only invoked when route matches */
getComponent (nextState, cb) {
/* Webpack - use 'require.ensure' to create a split point
and embed an async module loader (jsonp) when bundling */
require.ensure([], (require) => {
/* Webpack - use require callback to define
dependencies for bundling */
const Counter = require('./containers/ForumContainer').default
const reducer = require('./modules/forum').default
/* Add the reducer to the store on key 'forum' */
injectReducer(store, { key: 'forum', reducer })
/* Return getComponent */
cb(null, Forum)
/* Webpack named bundle */
}, 'forum')
}
})因此,使用上面的配置,当有人进入yourawesomepage.com/论坛时,所需的文件将被下载,负责论坛的reducer (来自redux)也将被注入。
This是一个开箱即用的小入门包。
https://stackoverflow.com/questions/42836585
复制相似问题