You should not use Route component and Route render in the same route

  • Post author:
  • Post category:其他


//You should not use <Route component> and <Route render> in the same route;
 //<Route render> will be ignored
 //这句话是不用在路由中再嵌套路由
 //错误写法
         <Route {...props} render={(item) => {
            if (item.isLogin) {
                return <Componet />
            } else {
                message.warning('你还没有登录,淘气鬼,让我把你送回去吧!');
                return <Redirect to={{ pathname: "/login" }} />
            }
        }} />
//改成
    if(props.isLogin) {
        return <Route {...props} componet={Componet}/>
    }else {
        message.warning('你还没有登录,淘气鬼,让我把你送回去吧!');
        return <Redirect to={{ pathname: "/login" }} />
    }



版权声明:本文为qq_44096635原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。