react路由

路由跳转使用:

this.props.history.push('路由地址')

如果使用this.props.history.push()报错的话:

import {withRouter} from ‘react-router-dom’

export default withRouter(组件名)

react接收参数 :

this.props.match.params.参数名 前提必须在Route配置参数 /:参数名

react路由守卫:

<Router>
    <Switch>
         <Route  path='/想要跳转的路由' render={()=>{
                return  localStorage.getItem('username') ?<如果localStorage存在值想要展示的页面/>  :<Redirect  to='重定向到登录页面'/>
          }} />
    </Switch>
</Router>
原文地址:https://www.cnblogs.com/xiaoxiaoxiongmao/p/12324303.html