Skip to content

Miss does not work with redux connect method. #4166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ralphsmith80 opened this issue Nov 9, 2016 · 3 comments
Closed

Miss does not work with redux connect method. #4166

ralphsmith80 opened this issue Nov 9, 2016 · 3 comments

Comments

@ralphsmith80
Copy link

Version

v4 master be62ac3

Test Case

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {Provider, connect} from 'react-redux'
import {createStore} from 'redux'
import {
  BrowserRouter as Router,
  Match,
  Miss,
  Link,
} from 'react-router'
// Not sure why this isn't working with destructuring
import MatchGroup from 'react-router/MatchGroup'


const store = createStore(function(state) {
  return state
})

class App extends Component {
  render() {
    return (
      <div>
        <ul>
          <li><Link to="/">Home</Link></li>
          <li><Link to="/foo">Foo</Link></li>
          <li><Link to="/Missed">Missed</Link></li>
        </ul>
        <MatchGroup>
          <Match pattern="/" exactly render={() => <h1>Home</h1>}/>
          <Match pattern="/foo" render={() => <h1>Foo</h1>}/>
          <Match pattern="/bar" render={() => <h1>Bar</h1>}/>
          <Miss render={({ location }) => (
            <div>Nothing matched {location.pathname}</div>
          )}/>
        </MatchGroup>
      </div>
    )
  }
}
function mapStateToProps(state) {
  return Object.assign({}, state);
}
App = connect(mapStateToProps)(App);

ReactDOM.render(
  <Provider store={store}>
    <Router>
      <App/>
    </Router>
  </Provider>, document.getElementById('root'))

Steps to reproduce

  • Load the app
  • Click the missed link

Expected Behavior

Component associated to Miss is rendered

Nothing matched /Missed

Actual Behavior

No component is rendered

More Info

If you click the link again then the component associated with Miss is rendered. This appears to be related to issue #4035. The issue occurs when App = connect(mapStateToProps)(App) is introduced. I'm not sure if this is an issue with redux doing something is shouldn't or the Miss implementation, but in anycase this is going to be an issue with applications that leverage Redux which is likely to be many.

@ralphsmith80
Copy link
Author

The Redux connect issue might be deeper than just the Miss case. Check out this pin which illustrates an issue even without the MatchGroup. If you comment out line 34 (the connect call) the links work as expected.

@ryanflorence
Copy link
Member

related to lots of other things, will have redux examples at launch

@ralphsmith80
Copy link
Author

ralphsmith80 commented Nov 9, 2016

Any ideas on when alpha.6 might come out? I'm satisfied with moving forward with what I can, given the MatchGroup addition, but an npm build from a commitish "react-router:" https://github.com/ReactTraining/react-router.git#be62ac357e910e3c9f48dd66c14cb8cdf69891d1 fails.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants