简体   繁体   English

处理来自外部服务器的重定向

[英]Handling redirection from an external server

I have a functionality where when a user clicks on a button, he/ she will be redirected to an external website, where once the work is complete user is navigated back to his/her original page with a query as follows, 我具有一项功能,当用户单击按钮时,他/她将被重定向到外部网站,一旦工作完成,用户将通过以下查询导航回到他/她的原始页面,

http://localhost:3000/settings/online-order?status=complete

What I require is, I need to perform an ajax call when the user is redirected with such a query. 我需要的是,当使用此类查询重定向用户时,我需要执行ajax调用。 I can do this on componentDidMount on my OnlineOrderComponent , but I don't know is it is correct. 我可以在OnlineOrderComponent上的componentDidMount上执行此OnlineOrderComponent ,但我不知道它是正确的。

I have defined my routes in a separate routes.js file and I tried handling it like this, 我已经在一个单独的routes.js文件中定义了我的路线,并尝试像这样处理它,

<Route path="settings/online-order" component={OnlineOrderComponent}/>
<Route path="settings/online-order?status=complete" onEnter={/*do something here*/}/>

Which seems very wrong. 这似乎很不对劲。 I would appreciate if any of you experts would just point me in the right direction to achieve this. 如果您有任何专家能为我指出实现这一目标的正确方向,我将不胜感激。 I apologize if this is vague and will clarify if required :) thanks 如果这含糊,我深表歉意,如有需要,请澄清:)谢谢

Using componentDidMount is probably the cleanest way. 使用componentDidMount可能是最干净的方法。 It seems like you are using react router. 看来您使用的是React Router。 You could do something like this: 您可以执行以下操作:

export Component extends React.Component {
    componentDidMount() {
        if (this.props.location.query.status && this.props.location.query.status === 'complete' ) {
            // do something
        } else {
            // do something else
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM