remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.06k stars 10.3k forks source link

Push/Replace called from createMemoryHistory is not causing Router to load the proper Route #7847

Closed DavidWnek closed 3 years ago

DavidWnek commented 3 years ago

Version

5.2.0

Test Case

https://codesandbox.io/s/peaceful-ptolemy-061ef?file=/src/MiniApp.js

Steps to reproduce

Backstory. I'm working on an application that has many small widgets that talk with each other and need to swap out other widgets all from a central dashboard.

My original thought was to make several small Router's with Memory History, and each widget can talk other widgets to change what path to render.

In my example, there's 4 App Windows with 5 "Apps" in it. When you click an App, it should go to the next page, do it's specific things, I added "dummy" controls to simulate what that App could potentially do, by opening a different app in a different window.

Expected Behavior

When you click a link to redirect to a new route, that route shows instead of the not found catch all.

Actual Behavior

When you click an App, it routes to the Not Found widget.

It looks like the history is tracking the change was made.

i.e. image

        <Router history={history}>
          <Switch>
            <Route path="/page/:name">
              <Page />
            </Route>
            <Route path="/">
              <List screen={index} />
            </Route>
            <Route>
              <NotFound />
            </Route>
          </Switch>
        </Router>
support[bot] commented 3 years ago

:wave: @DavidWnek, we use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. For usage questions, please use Stack Overflow or Reactiflux where there are a lot more people ready to help you out. Please feel free to clarify your issue if you think it was closed prematurely.

DavidWnek commented 3 years ago

@timdorr This is not support.... This is a bug

prevuelta commented 3 years ago

Yea, it's a bug... we ran into it too

cinan commented 3 years ago

I'm experiencing the same issue. Redirect calls history methods, but components aren't properly re-rendered. As a workaround I test history.location.pathname equality.

react-router: 5.2.1, jest/jsdom environment