AnApprentice
AnApprentice

Reputation: 110950

How to access the react-router-redux URL params from within a child component?

Given the following router:

import React, {Component} from 'react';
import {Route, Switch} from 'react-router-dom';
import {Provider as StoreProvider} from 'react-redux';
import {ConnectedRouter} from 'react-router-redux';

const App = ({store}) => {
  return (
          <StoreProvider store={store}>
            <ConnectedRouter history={history}>
              <Switch>
                <PrivateRoute path="/welcome/:welcomeId" layout={MainLayout} component={Welcome} />
              </Switch>
            </ConnectedRouter>
          </StoreProvider>
  );
};

import React from 'react'; import {connect} from 'react-redux';

class Welcome extends React.Component {
  constructor(props) {
    super(props);
    console.log('constructor');
    console.log(props.params);
  }
....

Why am I not getting props.params in the constructor?

Upvotes: 0

Views: 823

Answers (1)

Sebastiaan van Arkens
Sebastiaan van Arkens

Reputation: 447

If I remember correctly, the params can be accessed through the props.match.params

Upvotes: 3

Related Questions