Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用户如何正确响应路由器重定向?_Javascript_Reactjs_Redirect_Redux_React Router - Fatal编程技术网

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!='/')){
返回;
}
返回(
...
);
}