Apollo客户端+ NextJs身份验证问题

时间:2018-12-02 00:25:18

标签: reactjs react-apollo next.js

我正在使用React(NextJs)和Apollo Client开发Intranet应用程序。我需要限制所有页面。我想将未经身份验证的用户重定向到登录页面,但是在查询中出现以下错误:

Error: No router instance found. You should only use "next/router" inside the client side of your app.

查询正在工作,唯一的问题与路由器有关。为什么我无法从Query访问它以及如何解决它?

 return (
    <>
      <Meta/>
      <div className={classes.wrapper}>
        <CssBaseline/>
        <Header/>
        <main className={classes.content}>
          <Query query={CURRENT_USER_QUERY}>
            {({ data: { me } }) => {
              if(!me) {
                const { pathname } = this.props.router;
                if (pathname !== '/login') {
                  Router.push('/login');
                  return null;
                }
              }

              if (me) return (
                  <>
                    <div className={classes.toolbar}/>
                    {this.props.children}
                  </>
              );

              return <Login/>;
            }}
          </Query>
        </main>
      </div>
    </>
);

谢谢:)

0 个答案:

没有答案
相关问题