Javascript 用户如何正确响应路由器重定向?
我遇到了一个问题。 当我想重定向时,我收到此错误Javascript 用户如何正确响应路由器重定向?,javascript,reactjs,redirect,redux,react-router,Javascript,Reactjs,Redirect,Redux,React Router,我遇到了一个问题。 当我想重定向时,我收到此错误 您试图重定向到当前所在的同一路线:“/” 我的App.js文件如下所示 render(){ const{auth}=this.props; 如果(!auth.isauthenticified){ 返回; } 返回( ... ); }在重定向到该路径之前,您需要验证您是否已经在该路径上: import {withRouter} from 'react-router-dom'; // ... render() { const { aut
您试图重定向到当前所在的同一路线:“/”
我的App.js文件如下所示
render(){
const{auth}=this.props;
如果(!auth.isauthenticified){
返回;
}
返回(
...
);
}
在重定向到该路径之前,您需要验证您是否已经在该路径上:
import {withRouter} from 'react-router-dom';
// ...
render() {
const { auth } = this.props;
const {pathname} = this.props.location;
if (!auth.isAuthentificated && pathName !== '/') {
return <Redirect to="/" />;
}
return (
...
<Switch>
<Route path="/welcome" component={Welcome} />
<Route path="/user-info" component={UserInfo} />
<Route path="/" component={LoginPage} />
</Switch>
);
}
从“react router dom”导入{withRouter};
// ...
render(){
const{auth}=this.props;
const{pathname}=this.props.location;
如果(!auth.isauthenticified&&pathName!='/')){
返回;
}
返回(
...
);
}
在重定向到该路径之前,您需要验证您是否已经在该路径上:
import {withRouter} from 'react-router-dom';
// ...
render() {
const { auth } = this.props;
const {pathname} = this.props.location;
if (!auth.isAuthentificated && pathName !== '/') {
return <Redirect to="/" />;
}
return (
...
<Switch>
<Route path="/welcome" component={Welcome} />
<Route path="/user-info" component={UserInfo} />
<Route path="/" component={LoginPage} />
</Switch>
);
}
从“react router dom”导入{withRouter};
// ...
render(){
const{auth}=this.props;
const{pathname}=this.props.location;
如果(!auth.isauthenticified&&pathName!='/')){
返回;
}
返回(
...
);
}