码迷,mamicode.com
首页 > 其他好文 > 详细

react router问题, 找不到history

时间:2020-05-05 12:48:39      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:highlight   def   跳转   rop   style   router   with   row   pat   

首先,在路由页面,引入了一个组件。RouteDemo 

<BrowserRouter>
        {/* 没通过 <Route /> 匹配路由的  默认拿不到history的*/} 
        <RouteDemo />

        <Switch> 
          <Route path=‘/table‘ component={TableDemo}/>
        </Switch>
 </BrowserRouter>

  

在RouteDemo 页面 使用props 是一个空{},如果需要使用路由跳转,如何处理

首先先引入 withRouter 
import { withRouter } from ‘react-router-dom‘

export default @withRouter  这里我使用的是e7的修饰器, @

  

这样在RouteDemo 就能拿到props了。

react router问题, 找不到history

标签:highlight   def   跳转   rop   style   router   with   row   pat   

原文地址:https://www.cnblogs.com/yetiezhu/p/12830188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!