function Navigation() {
return (
<div className="nav">
<Link to="/">Home</Link>
<Link to={{
pathname:"/about",
state: {
fromNavigation: true
}
}}>About</Link>
</div>
);
}
undefined
일 경우 home으로 Redirect하는 코드class Detail extends React.Component{
componentDidMount(){
const { location, history } = this.props;
if(location.state === undefined) {
history.push("/");
}
}
render(){
return <span>hello</span>
}
}