Skip to content

history.push not rendering component in Router #7415

@riwu

Description

@riwu

Version

"react-router-dom": "^5.2.0", 

Test Case

For some peculiar reason this bug is not reproducible on CodeSandbox, please clone https://github.com/riwu/react-router-dom-bug instead.

import React from "react"; import { Router, Route } from "react-router-dom"; import { createBrowserHistory } from "history"; const history = createBrowserHistory(); export default function App() { return ( <Router history={history}> <Route exact path="/" component={() => ( <button onClick={() => history.push("/2")}>click</button> )} /> <Route path="/2" component={() => "page 2"} /> </Router> ); } 

Steps to reproduce

  1. git clone https://github.com/riwu/react-router-dom-bug.git
  2. yarn install
  3. yarn start
  4. Click the "click" button.

Expected Behavior

"page 2" should be rendered.

Actual Behavior

blank page is rendered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions