简体   繁体   English

如何使用React从ajax调用成功后重定向?

[英]How to redirect after success from ajax call using React?

I'm new on using ReactJS and I want to know how to redirect after success from ajax call using React without react-route or flux ? 我是使用ReactJS的新手,我想知道如何使用React在没有react-route或flux的情况下从ajax调用成功后重定向? Is that possible ? 那可能吗 ? Can someone help me please 有人能帮助我吗

您可以在ajax回调中更改window.location.href,以将浏览器重定向到新的URL。

I've not played much with React with React-routes. 我没有玩React和React-routes。 But You can use JS version. 但是您可以使用JS版本。

// similar behavior as an HTTP redirect 
window.location.replace("http://stackoverflow.com"); 

// similar behavior as clicking on a link 
window.location.href = "http://stackoverflow.com";

Source from LINK 来自LINK的消息来源

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

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