我有privateRoute。当用户未登录或电子邮件未验证时,请重定向到带有警告的模态登录。它是由函数显示模式运行的,但我得到了错误。这是工作,它在dev中显示了这个错误。我不明白这个错误。
警告:
index.js:1警告:不能在呈现其他组件(
Context.Consumer)时更新组件(App)。要在Context.Consumer中找到坏的Context.Consumer()调用,请按照Context.Consumer中的路由(at PrivateRoute.js:13)、PrivateRoute (at App.js:217)中的路由(at App.js:217)、路由器中的路由器(由BrowserRouter创建)中的堆栈跟踪(由BrowserRouter创建)、应用程序(at App.js:139)中的div (at App.js:139)中的BrowserRouter (at App.js:139)、应用程序(at src/index.js:11)中的提供者( src/index.js:10)中描述的堆栈跟踪。
代码:
<Route
{...rest}
render={(props) =>
(user && user.providerId && user.providerId !== 'password') ||
(user &&
user.providerId &&
user.providerId === 'password' &&
user.emailVerified) ? (
<Component {...props} />
) : (
<Redirect to="/">{setLoginModalShow(true)}</Redirect>
)
}
/>我该怎么做呢--请帮忙
发布于 2020-12-19 14:59:34
不要在重定向时调用setLoginModalShow(true),而是尝试下面的方法,在重定向到主页和主页时传递一些标志作为操作,检查路由器是否有此标志,并使用它显示登录模式。
<Redirect
to={{
pathname: "/",
state: { action: "showLogin" }
}}
/>https://stackoverflow.com/questions/65370845
复制相似问题