Reactjs 阿波罗2.1,突变与反应路由器

Reactjs 阿波罗2.1,突变与反应路由器,reactjs,react-router-v4,react-apollo,mutation,Reactjs,React Router V4,React Apollo,Mutation,我是阿波罗的新手,从2.1版开始 我也使用react路由器,但我不知道如何在变异完成后进行browserHistory.push。以下是我的部分代码: index.js const客户端=新客户端({ uri:“http://localhost:4000/graphql" }); ReactDOM.render( , document.getElementById('react\u root')) ) }) 在onCompleted中,我想显示一个不同的页面,告诉用户检查电子邮件。但我不知道怎

我是阿波罗的新手,从2.1版开始

我也使用react路由器,但我不知道如何在变异完成后进行browserHistory.push。以下是我的部分代码:

index.js

const客户端=新客户端({
uri:“http://localhost:4000/graphql"
});
ReactDOM.render(
,
document.getElementById('react\u root'))
)
})

在onCompleted中,我想显示一个不同的页面,告诉用户检查电子邮件。但我不知道怎么做

RegistrationForm.js

从'react router'导入{browserHistory];
const onCompleted=(数据)=>{
browserHistory.push(“/de/register/check email”);
}
const RegistrationForm=()=>{
返回(
{(寄存器,{data})=>(
(
{
e、 预防默认值();
登记册({
变量:{
输入:{
用户名:values.username,
电子邮件:values.email,
密码:values.password
}
}
});
}}
>
用户名
电子邮件
密码
提交
)}
/>
)}
);
};
有人知道怎么做吗?非常感谢你的帮助


致以最诚挚的问候

我想我找到了解决办法。我将历史作为道具从调用组件传递,然后使用:

const RegistrationFinalForm = ({ history }) => {
    return (
        <Mutation mutation={REGISTER_USER}
            onCompleted={(data) => {
                history.push("/de/register/check-email");
            }}>
const RegistrationFinalForm=({history})=>{
返回(
{
历史记录。推送(“/de/register/check email”);
}}>

react router
中没有导出
浏览器历史记录
,但有一个
历史记录
道具

如果您的组件位于
下,您可以这样使用它:

const RegistrationForm = ({history}) => {
  const onCompleted = (data) => {
    history.push("/de/register/check-email");
  }

  return (
  ..
如果您的组件在树中较深,您可以将
历史
和其他路由道具与
with router
一起注入,例如:

const RegistrationFormWrapped = withRouter(RegistrationForm);

由于
onCompleted
现在依赖于一个道具,并且需要是本地的,因此将
RegistrationForm
转换为类是有意义的

export default withRouter(RegistrationForm);