Access parameters using reaction-router-reduct

I am using response-router-redux ( https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux )

installed with

npm install --save react-router-redux@next

runs like this:

<Route path='/resource/:id' component={Resource}/>

I am trying to access the id parameter in a container, for example:

const mapStateToProps = (state, ownProps) => {
  console.log(ownProps)
  return {...state.resource, id: ownProps.params.id}
}

As shown in the doc-router-abbreviation docs.

I get an error indicating that ownProps.params is undefined. So this works:

const mapStateToProps = (state, ownProps) => {
  return {...state.resource, id: ownProps.match.params.id}
}

However, when I register my ownProps, I find that ownProps.match.params.id contains the required identifier.

Is this a change in implementation or have I used the route incorrectly? Thanks

+4
2

npm install --save react-router-redux@next

, , - react-router-redux 5, action-router v4.

https://github.com/reactjs/react-router-redux readme, react-router-redux 5 - .

-router-redux 4.x, 2.x 3.x

response-router-redux 5.0.0 4.x. .

, , , .

, params match Props.

+5

, , , - .

, , match:

import { createMatchSelector } from 'react-router-redux';

const { params } = createMatchSelector({ path: '/resource/:id' })(state);

console.log(params.id); 

redux-saga, . react-router props.match.params.id

+3

Source: https://habr.com/ru/post/1675472/


All Articles