首页 > 解决方案 > 为什么 history.push 不会使用 react-router-dom 重定向到新组件?

问题描述

我有 2 个组件都完全相同。当我单击使用 react-bootstrap 创建的导航栏中的 Navlink 时,将重定向到一个。当我单击应该重定向到该组件的 html 按钮时,不会加载完全相同的另一个组件。请帮我。

html按钮和重定向功能看起来像

const getProfile = async (member) => {
 //   const addr = dispatch({ type: 'ADD_MEMBER', response: member })
    console.log(member)
    history.push('/member')

}

    <button onClick={() => getProfile(p.publisher)}>Profile</button> 

routes.js 看起来像

const Routes = (props) => {
  return (
      <Switch>

      <Route path="/member" exact component={Member} /> 

      </Switch>
    
  )
}

export default Routes

我尝试重定向到的组件与我从导航链接单击它时重定向到并正在工作的组件完全相同

标签: javascriptreactjsreact-router

解决方案


推荐阅读