当未使用react路由器<Route />而呈现react组件时,我可以更改窗口位置吗?
{
this.state.loading ?
( <Loader percentageLoadingProgress={this.state.percentageLoadingProgress} loadingInformation={this.state.loadingInformation} /> ) :
( <Companies {...this.state} /> )
}我需要用更改的窗口位置呈现<Companies />
发布于 2020-06-05 05:02:37
您可以返回一个Redirect,例如:
const someComponent = props => {
if (props.foo) return `<Redirect to="/somewhere/else" />`;
return <NormalUI />;
}也可以使用useHistory钩子获取history对象,然后调用history.push('/somewhere/else')
const someComponent = props => {
const history = useHistory();
if (props.foo) history.push('/somewhere/else');
else return <NormalUI />;
}Redirect组件是首选的方法。
https://stackoverflow.com/questions/62208258
复制相似问题