服务器端代码:
router.get('/*', function(ctx, next) {
const context = {};
const initialState = {};
const appStore = createAppStore(null, initialState);
const appString = ReactDOMServer.renderToString(
<Provider store={appStore} key="provider">
<StaticRouter location={ctx.url} context={context}>
{renderRoutes(routes)}
</StaticRouter>
</Provider>
);
...
(路由 - 只是来自示例页面的copypast) 在某些路线上请求后,我总是得到主页
如果我使用自己的路线
const routes =
[
{ path: '/',
exact: true,
component: Home
},
{ path: '/about',
component: About
}
]
在两条路线上我也获得了主页,点击链接不工作,不记录任何错误
我的回购:https://github.com/kirsanv43/react-universal-starter-kit/blob/master/src/server.js