简体   繁体   English

第 4:27 行:道具验证反应/道具类型中缺少“组件”

[英]Line 4:27: 'component' is missing in props validation react/prop-types

I am very new to react and when i am trying to run the code this is the error i am getting我对反应很陌生,当我尝试运行代码时,这是我得到的错误

Line 4:27: 'component' is missing in props validation react/prop-types第 4:27 行:道具验证反应/道具类型中缺少“组件”

import React from 'react'
import { Navigate, Route } from 'react-router-dom'

function ProtectedRoute({ component: Component, ...restOfProps }) {
const isAuthenticated = localStorage.getItem('isAuthenticated')
console.log('this', isAuthenticated)

return (
<Route
  {...restOfProps}
  render={(props) => (isAuthenticated ? <Component {...props} /> : <Navigate to="/Login" />)}
/>
)
}

export default ProtectedRoute

i am using latest version of react will apricate any help我正在使用最新版本的 react 将提供任何帮助

import React from 'react'
import { Navigate, Route } from 'react-router-dom'

function ProtectedRoute({ component, ...restOfProps }) {
const isAuthenticated = localStorage.getItem('isAuthenticated')
console.log('this', isAuthenticated)

return (
<Route
  {...restOfProps}
  render={(props) => (isAuthenticated ? <Component {...props} /> : <Navigate to="/Login" />)}
/>
)
}

export default ProtectedRoute
import React from "react";
import { Navigate, Route } from "react-router-dom";

function ProtectedRoute({ Component, ...restOfProps }) {
  const isAuthenticated = localStorage.getItem("isAuthenticated");
  console.log("this", isAuthenticated);

  return (
    <Route
      {...restOfProps}
      render={(props) => (isAuthenticated ? <Component {...props} /> : <Navigate to="/Login" />)}
    />
  );
}

export default ProtectedRoute;

try this one试试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM