0

我尝试从https://github.com/ReactTraining/react-router/blob/master/packages/react-router-config/README.md#renderroutesroutes运行示例

服务器端代码:

 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>
   );
  ...

(路线 - 只是从示例页面复制过去)在某些路线上请求后,我总是得到主页

如果我使用自己的路线

const routes =
[
  { path: '/',
    exact: true,
    component: Home
  },
  { path: '/about',
    component: About
  }
]

在两条路线上,我还获得了主页,单击 Link don't work 并且不记录任何错误

我的仓库:https ://github.com/kirsanv43/react-universal-starter-kit/blob/master/src/server.js

4

1 回答 1

0

不知道为什么,但是当我将 renderRoutes 函数从 react-router-config复制到我的项目并使用它时,一切都很好。

于 2017-03-27T13:11:54.237 回答