// jsx 模式
<Redirect to="/somewhere/else" />
// event 模式
import React from 'react'
import { Redirect } from 'react-router-dom'class MyComponent extends React.Component { state = {
redirect: false
} setRedirect = () => {
this.setState({
redirect: true
})
} renderRedirect = () => {
if (this.state.redirect) {
return <Redirect to='/target' />
}
} render () {
return (
<div>
{this.renderRedirect()}
<button onClick={this.setRedirect}>Redirect</button>
</div>
)
}}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…