【发布时间】:2018-07-29 20:57:28
【问题描述】:
我有一个表单组件,我正在单击下一步按钮对该表单进行验证,一旦验证成功,我想呈现一个不同的组件。
在状态中,我将“showComponent”保持为假,单击该按钮时,我将其设为真。
_onButtonClick (event){
event.preventDefault();
this.setState({
...this.state,
showComponent: !this.state.showComponent
})
console.log("button clicked",this.state);
}
按键逻辑:
<div>
<button onClick={(event) => this._onButtonClick(event)}>Button</button>
{this.state.showComponent ?<AddModules /> : null}
</div>
我能够渲染那个新页面,但它在同一页面上渲染,这是我不想要的。
【问题讨论】:
-
我相信您在通过
<Route />组件声明组件时可能没有使用exact关键字。确保在声明路由时仅在路由与确切路径匹配时才加载组件,这样声明它: -
谢谢,我已经这样做了,但是路径问题存在,谢谢您的指导。
标签: reactjs react-native react-router