Reactjs React JS组件中的重定向问题

Reactjs React JS组件中的重定向问题,reactjs,redirect,conditional,jsx,Reactjs,Redirect,Conditional,Jsx,我试图通过组件文件中的条件语句重定向到其他组件 myfile.js的片段 import { Redirect } from 'react-router-dom'; render(){ if (isLoggedIn()) { return( <Redirect to='/Myaccount' /> ); } } 从'react router dom'导入{R

我试图通过组件文件中的条件语句重定向到其他组件

myfile.js的片段

import { Redirect } from 'react-router-dom';
render(){
        if (isLoggedIn()) {
            return(
                <Redirect to='/Myaccount' />
            );
        }   
    } 
从'react router dom'导入{Redirect};
render(){
if(isLoggedIn()){
返回(
);
}   
} 
如果条件为true,则会更改浏览器的url,但不会加载内容。

请让我知道我做错了什么。

您最好使用
历史记录。按如下按钮

if (isLoggedIn()) {
   return(
       this.props.history.push("/Myaccount");
   );
}   

您最好使用
历史记录。按一下类似的按钮

if (isLoggedIn()) {
   return(
       this.props.history.push("/Myaccount");
   );
}   

但是,您不会返回它,也不会在渲染中使用它function@Drum>this.props.history.push(“/Myaccount”);>>我试过了,但也不起作用……不过你不会返回,也不会在渲染中使用它function@Drum>this.props.history.push(“/Myaccount”);>>我试过了,但也不起作用…检查这个答案,我想这将回答你的问题相同,重定向…浏览器中的url已更改,但页面内容未加载…你是否使用withRouter,也是否有任何错误,或者你是否有匹配的RouteEyes,我使用“withRouter”作为..>>>>
从“react router dom”导入{withRouter}
>>>>
componentDidMount(){if(isLoggedIn()){this.props.history.push('/Myaccount');}}
>>>>
导出默认连接(MapStateTrops,mapDispatchToProps)(带路由器(登录))我在控制台中没有收到任何错误,这个
从“react router”导入{withRouter}检查此答案,我想这将回答您的问题相同,重定向……浏览器中的url已更改,但页面内容未加载……您是否使用withRouter,是否也收到任何错误,或者您是否有匹配的RouteEyes,我用“withRouter”作为..>>>
从“react router dom”导入{withRouter}
>>>>
componentDidMount(){if(isLoggedIn()){this.props.history.push('/Myaccount');}}
>>>>
导出默认连接(MapStateTrops,mapDispatchToProps)(带路由器(登录))我在控制台中没有收到任何错误,这个
从“react router”导入{withRouter}