在我的Next.js组件中,我向GraphQL服务器发出了一个变异请求,成功完成后,我需要重定向到另一个页面。我现在该如何做:
import React, { Component } from 'react';
import Router from 'next/router';
import { Mutation } from 'react-apollo';
import { gql } from 'apollo-boost';
const signInMutation = gql`
mutation signIn($accessToken: String!) {
signIn(accessToken: $accessToken)
}
`;
export default class extends Component {
static async getInitialProps({ query: { accessToken } }) {
return { accessToken };
}
render() {
const { accessToken } = this.props;
return (
<Mutation mutation={signInMutation} ignoreResults>
{signIn => {
signIn({ variables: { accessToken } }).then(() => {
Router.push({
pathname: '/user'
});
});
return null;
}}
</Mutation>
);
}
}
它工作正常,但Next.js引发错误:You should only use "next/router" inside the client side of your app.
。那么,解决错误的最佳方法是什么?