【发布时间】:2016-05-06 20:16:06
【问题描述】:
我有一个高阶组件(由下面的wrapAuthComponent 应用),它封装了任何需要身份验证的组件。该组件检查用户是否登录,如果没有,则重定向:
let next = this.props.location.pathname;
this.context.router.push({
pathname: '/login',
query: {...this.props.location.query, next}
});
另外,我有一个允许用户登录的导航栏组件:
<IndexLinkContainer to={`/login? next=${this.props.pathname}`}>
<NavItem className='nav-bar-button'> Login </NavItem>
</IndexLinkContainer>
(上面的pathname prop 是由App 容器传递的)
所以,回顾一下,我的路线是这样绘制的:
<Route component={App} /* app contains the above navbar */ path="/">
<Route component={LoginPage} path="/login" />
<Route component={wrapAuthComponent(Foo)} path="/foo" />
</Route>
现在,进入错误。 当我转到/foo 并且没有登录时,我收到以下错误:
React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) href="/login?next=/login" data-reactid=
(server) href="/login?next=/foo" data-reactid="
我在这里做错了什么?
【问题讨论】:
-
你使用的是什么版本的 Node.js 和 React?
标签: javascript reactjs react-router redux isomorphic-javascript