Connected-react-router: How can I access the params

Created on 30 Jun 2018  路  7Comments  路  Source: supasate/connected-react-router

I managed to make this work in my project, however, I don't see params.
location: hash:"" key:"aymkl8" pathname: "/about/mo/18HHaYQSUs6WUWIOMaYYiI" search:""

I need to access the id (18HHaYQSUs6WUWIOMaYYiI) in MapStateToProps. I see the id in the params normally inside the component.

Most helpful comment

What's the reason? To access matched params through ownProps you would need to wrap your components in withRouter HOC which entirely defeats the purpose of using this lib. What am I missing?

All 7 comments

There is a reason why route params are not included in redux state. What you probably want is this.

const mapState = (state, ownProps) => {
  const { id } = ownProps.match.params
   // rest of your mapState code
}

Thank you very much, that works.

What's the reason? To access matched params through ownProps you would need to wrap your components in withRouter HOC which entirely defeats the purpose of using this lib. What am I missing?

@em see here.

How about accessing params from a custom redux middleware that dispatches actions based on location changes

Hello there, any news on gettings the params from a redux reducer?

Actually, there is a ticket still opened on this topic
https://github.com/supasate/connected-react-router/issues/38

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AdrienLemaire picture AdrienLemaire  路  5Comments

nickvoronin-ellation picture nickvoronin-ellation  路  5Comments

preciselywilliam picture preciselywilliam  路  4Comments

BerndWessels picture BerndWessels  路  3Comments

abeledovictor picture abeledovictor  路  3Comments