Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Reactjs 如何解决自定义路由组件中禁止道具传播的问题?_Reactjs_Eslint_React Router Dom - Fatal编程技术网

Reactjs 如何解决自定义路由组件中禁止道具传播的问题?

Reactjs 如何解决自定义路由组件中禁止道具传播的问题?,reactjs,eslint,react-router-dom,Reactjs,Eslint,React Router Dom,如何解决自定义路由组件中禁止道具传播的问题 eslint:禁止在3号线和6号线上传播道具 const PrivateRoute = ({component: Component, ...rest}) => ( <Route {...rest} render={(props) => ( localStorage.getItem('user') ? <Component {...props} /> :

如何解决自定义路由组件中禁止道具传播的问题

eslint:禁止在3号线和6号线上传播道具

const PrivateRoute = ({component: Component, ...rest}) => (
  <Route
    {...rest}
    render={(props) => (
        localStorage.getItem('user') ?
          <Component {...props} /> :
          <Redirect to={{pathname: '/login', state: {from: props.location}}} />
  )}
  />
);
const PrivateRoute=({component:component,…rest})=>(
(
localStorage.getItem('user')?
:
)}
/>
);

ES lint不鼓励使用道具撒布,以便不会将不需要的/意外的道具传递到组件。 详情如下:

要为特定文件禁用它,可以在组件文件的顶行放置:
/*eslint disable react/jsx props no spreading*/
。 要对所有文件禁用它,请尝试以下操作:


根据以下答案编辑的评论对于ESLint很重要您使用哪种类型的评论,合法的是:

/* eslint-disable react/jsx-props-no-spreading */

谢谢你!我添加了一条规则“react/jsx props no spreading”:[“error”,{“custom”:“ignore”}],它解决了这个问题。。。我的头撞在墙上太久了。注释类型显然很重要。