gpt4 book ai didi

reactjs - 使用 React Router 组件进行重定向

转载 作者:行者123 更新时间:2023-12-03 13:26:05 24 4
gpt4 key购买 nike

我遇到了 react-router-component 的问题。我正在尝试创建一个 redirect 库,它可以执行“软”重定向(相当于单击链接,而不是 window.location = ...)可以从 .jsx 组件中获取。

Per the docs我应该能够调用 router.navigate(path) 进行重定向。

例如,当我在页面 A 上调用此方法时,地址栏中的 URL 会根据需要更改为页面 B。但是,页面 A 只是重新加载,将地址栏保留为页面 B,并将显示保留为页面 A。有建议吗?

最佳答案

您应该能够使用导航混合解决此问题。

然后您可以将 this.transitionTo 与您的页面名称一起使用。

var PageAdd = React.createClass({

mixins : [Router.Navigation],

handleSubmit : function(e) {
e.preventDefault();

this.transitionTo('pages');

},

render: function () {
return (
<form onSubmit={this.handleSubmit}>
<button type="submit" className="btn btn-default">Submit</button>
</form>
);
}
});

了解更多:https://github.com/rackt/react-router/blob/master/docs/api/mixins/Navigation.md

关于reactjs - 使用 React Router 组件进行重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25374945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com