I've currently changed my routing around a bit to support certain routes having different, arbitrary layouts. The scheme works on all views other than when I need to pass a value via route to the component. For example, I have the following route defined:
function renderWithLayout(Component, Layout) {
return <Layout><Component /></Layout>
}
export default class App extends Component {
displayName = App.name;
render() {
<ApolloProvider client={client}>
<Route
path="/articles/view/:id"
render={() => renderWithLayout(ArticlesView, PublicLayout)}
exact={true}
/>
</ApolloProvider>
}
}
then in my ArticlesView component, I am attempting to grab the id
passed to the route as follows in the render()
method:
const { match: params } = this.props;
console.log(params); //this is undefined
var id = params.id; //TypeError: Cannot read property 'id' of undefined
before I changed the routing around, I could just do const { id } = this.props.match.params;
how can I overcome this issue?
EDIT: before the routing change, I had the route defined as:
<Route
path="/articles/view/:id"
component={ArticlesView}
exact={true}
/>