所以我在 React 中使用 PrivateRoute
来提供一些组件。一切正常,直到我指定了如下所示的确切路径:
<PrivateRoute exact path="/info/:id" render={(props) => <BookInfo {...props} />} />
如果我正常使用 Route
提供服务,上面的路径工作正常,但是通过 PrivateRoute
路由给我以下错误。
PrivateRoute.js
import React from 'react'
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
const PrivateRoute = ({ component: Component, auth, ...rest}) => (
<Route {...rest} render={ props =>
auth.isAuthenticated === true ?
(<Component {...props}/>) : (<Redirect to ='/login'/>)}/>
)
const mapStateToProps = state => ({
auth: state.auth
})
export default connect (mapStateToProps)(PrivateRoute);
我不知道是什么原因造成的,非常感谢您的帮助。
答案 0 :(得分:2)
您的 import paramiko
rsa_key = paramiko.RSAKey.from_private_key_file("C:/locationof/privkey", password='password')
csv = "C:/locationof/DELETE_users_snapshot.csv"
dest = "/upload/DELETE_users_snapshot.csv"
transport = paramiko.Transport(("host",4911))
transport.connect(username='user', pkey=rsa_key)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(csv,dest)
组件期望传递一个 Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 0
Status: Connecting to host:4911...
Trace: Going to execute C:\Program Files\FileZilla FTP Client\fzsftp.exe
Response: fzSftp started, protocol_version=10
Trace: CSftpConnectOpData::ParseResponse() in state 0
Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 2
Command: keyfile "C:\Users\me\Documents\privkey"
Trace: CSftpConnectOpData::ParseResponse() in state 2
Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 3
Command: open "user@host" 4911
Trace: Looking up host "host" for SSH connection
Trace: Connecting to host port 4911
Trace: We claim version: SSH-2.0-FileZilla_3.52.0.1
Trace: Remote version: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
Trace: Using SSH protocol version 2
Trace: Doing ECDH key exchange with curve Curve25519 and hash SHA-256 (unaccelerated)
Trace: Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
Trace: Host key fingerprint is:
Trace: ssh-ed25519 255 b6:bf:f6:7d:d5:ee:25:b9:b3:da:94:03:ce:16:bf:e6 iYh1W2ce0YiCyZo19PktVYQJwrYqjmn6qaopbW0HIzQ=
Trace: Initialised AES-256 GCM outbound encryption
Trace: Initialised AES256 GCM outbound MAC algorithm (in ETM mode) (required by cipher)
Trace: Initialised AES-256 GCM inbound encryption
Trace: Initialised AES256 GCM inbound MAC algorithm (in ETM mode) (required by cipher)
Trace: Private key in 'C:\Users\me\Documents\privkey' is encrypted, defer loading until use.
Trace: Successfully loaded 1 key pair from file
Status: Using username "user".
Trace: Offered public key from "C:\Users\me\Documents\privkey"
Trace: Offer of public key accepted, trying to authenticate using it.
Trace: CSftpControlSocket::SetAsyncRequestReply
Command: Pass: ********
Trace: Sent public key signature
Trace: Access granted
Trace: Opening main session channel
Trace: Opened main channel
Trace: Started a shell/command
Status: Connected to host
Trace: Remote working directory is /upload
Trace: CSftpConnectOpData::ParseResponse() in state 3
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpConnectOpData::Reset(0) in state 3
Trace: CControlSocket::SendNextCommand()
Trace: CSftpListOpData::Send() in state 0
Status: Retrieving directory listing...
Trace: CSftpChangeDirOpData::Send() in state 0
Trace: CSftpChangeDirOpData::Send() in state 1
Command: pwd
Response: Current directory is: "/upload"
Trace: CSftpChangeDirOpData::ParseResponse() in state 1
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpChangeDirOpData::Reset(0) in state 1
Trace: CSftpListOpData::SubcommandResult(0) in state 1
Trace: CControlSocket::SendNextCommand()
Trace: CSftpListOpData::Send() in state 2
Trace: CSftpListOpData::Send() in state 3
Command: ls
Status: Listing directory /upload
Trace: CSftpListOpData::ParseResponse() in state 3
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpListOpData::Reset(0) in state 3
Status: Directory listing of "/upload" successful
Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 0
Status: Connecting to host:4911...
Trace: Going to execute C:\Program Files\FileZilla FTP Client\fzsftp.exe
Response: fzSftp started, protocol_version=10
Trace: CSftpConnectOpData::ParseResponse() in state 0
Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 2
Command: keyfile "C:\Users\me\Documents\privkey"
Trace: CSftpConnectOpData::ParseResponse() in state 2
Trace: CControlSocket::SendNextCommand()
Trace: CSftpConnectOpData::Send() in state 3
Command: open "user@host" 4911
Trace: Looking up host "host" for SSH connection
Trace: Connecting to host port 4911
Trace: We claim version: SSH-2.0-FileZilla_3.52.0.1
Trace: Remote version: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
Trace: Using SSH protocol version 2
Trace: Doing ECDH key exchange with curve Curve25519 and hash SHA-256 (unaccelerated)
Trace: Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
Trace: Host key fingerprint is:
Trace: ssh-ed25519 255 b6:bf:f6:7d:d5:ee:25:b9:b3:da:94:03:ce:16:bf:e6 iYh1W2ce0YiCyZo19PktVYQJwrYqjmn6qaopbW0HIzQ=
Trace: Initialised AES-256 GCM outbound encryption
Trace: Initialised AES256 GCM outbound MAC algorithm (in ETM mode) (required by cipher)
Trace: Initialised AES-256 GCM inbound encryption
Trace: Initialised AES256 GCM inbound MAC algorithm (in ETM mode) (required by cipher)
Trace: Private key in 'C:\Users\me\Documents\privkey' is encrypted, defer loading until use.
Trace: Successfully loaded 1 key pair from file
Status: Using username "user".
Trace: Offered public key from "C:\Users\me\Documents\privkey"
Trace: Offer of public key accepted, trying to authenticate using it.
Trace: CSftpControlSocket::SetAsyncRequestReply
Command: Pass: ********
Trace: Sent public key signature
Trace: Access granted
Trace: Opening main session channel
Trace: Opened main channel
Trace: Started a shell/command
Status: Connected to host
Trace: Remote working directory is /upload
Trace: CSftpConnectOpData::ParseResponse() in state 3
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpConnectOpData::Reset(0) in state 3
Trace: CControlSocket::SendNextCommand()
Trace: CSftpFileTransferOpData::Send() in state 0
Status: Starting upload of C:\Users\me\Documents\DELETE_snapshot.csv
Trace: CSftpChangeDirOpData::Send() in state 0
Trace: CSftpChangeDirOpData::Send() in state 2
Command: cd "/upload"
Response: New directory is: "/upload"
Trace: CSftpChangeDirOpData::ParseResponse() in state 2
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpChangeDirOpData::Reset(0) in state 2
Trace: CSftpFileTransferOpData::SubcommandResult(0) in state 1
Trace: CControlSocket::SendNextCommand()
Trace: CSftpFileTransferOpData::Send() in state 4
Command: put "C:\Users\me\Documents\DELETE_snapshot.csv" "DELETE_snapshot.csv"
Command: local:C:\Users\me\Documents\DELETE_snapshot.csv => remote:/upload/DELETE_snapshot.csv
Trace: CSftpFileTransferOpData::ParseResponse() in state 4
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpFileTransferOpData::Reset(0) in state 4
Status: File transfer successful, transferred 75 bytes in 1 second
Trace: CControlSocket::SendNextCommand()
Trace: CSftpListOpData::Send() in state 0
Status: Retrieving directory listing of "/upload"...
Trace: CSftpChangeDirOpData::Send() in state 0
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpChangeDirOpData::Reset(0) in state 0
Trace: CSftpListOpData::SubcommandResult(0) in state 1
Trace: CControlSocket::SendNextCommand()
Trace: CSftpListOpData::Send() in state 2
Trace: CSftpListOpData::Send() in state 3
Command: ls
Status: Listing directory /upload
Trace: CSftpListOpData::ParseResponse() in state 3
Trace: CControlSocket::ResetOperation(0)
Trace: CSftpListOpData::Reset(0) in state 3
Status: Directory listing of "/upload" successful
道具,它不处理 PrivateRoute
组件处理的其他道具。
component
将您的 Route
传递到 const PrivateRoute = ({
component: Component, // <-- only handles component prop
auth, ...rest
}) => (
<Route {...rest} render={ props =>
auth.isAuthenticated === true ?
(<Component {...props}/>) : (<Redirect to ='/login'/>)}/>
)
道具上,使其通过管道。
BookInfo
重构您的 component
组件,以呈现传递给它的所有道具的 <PrivateRoute exact path="/info/:id" component={BookInfo} />
或 PrivateRoute
组件。
Route