【Link】
Link标签,用于实现React-Router功能的跳转。(意思是就不要使用a标签了)
1)to:string,指明要跳转的path。
import { Link } from 'react-router-dom'
<Link to="/about">About</Link>
2)Link的牛逼之处,就是可以拼完整url。
to:object,指明要跳转的path、query、state。
<Link to={{ pathname: '/courses', search: '?sort=name', hash: '#the-hash', state: { fromDashboard: true } }}/>
3)replace,When true
, clicking the link will replace the current entry in the history stack instead of adding a new one.
<Link to="/courses" replace />
【Redirect】
Redict会直接跳转到新地址。
import { Route, Redirect } from 'react-router' <Route exact path="/" render={() => ( loggedIn ? ( <Redirect to="/dashboard"/> ) : ( <PublicHomePage/> ) )}/>
参考:https://reacttraining.com/react-router/web/guides/quick-start