【发布时间】:2019-05-31 06:39:43
【问题描述】:
当我点击提交按钮时,我需要重定向到这个页面 pageOne,所以我用谷歌搜索并找到了一个反应路由器并使用了这一行 this.props.history.push("/anotherPage");,但它没有重定向。
它抛出一个错误不变量失败:You should not use <Route> outside a <Router>
你能告诉我如何解决它。
在下面提供我的代码 sn-p 和沙箱。
https://codesandbox.io/s/material-demo-n9o7s
<!-- language-all: lang-or-tag-here -->
anotherPage = () => {
console.log("redictToStepper --->");
this.props.history.push("/anotherPage");
};
render() {
const { classes } = this.props;
const { checkBoxvalues } = this.state;
return (
<div className={classes.root}>increase when I hit submit button</div>
);
}
export default withRouter(withStyles(styles)(RadioButtonsGroup));
【问题讨论】:
-
您需要一个
组件,但我也认为您在应用程序中使用的 withRouter 太高了。将演示中的表单抽象到另一个组件并在演示级别构建您的路线。查看reacttraining.com/react-router/web/guides/quick-start的示例
标签: javascript html css reactjs redux