-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Closed
Description
Hi, I'm in the process of upgrading to react-router 4 from v2. I'm not sure if this is a bug or not, but I'm having a really hard time getting my Header component to show the correct route params object. It doesn't seem like the match.params object is available globally like the params object was in react-router 2 and I'm not sure how to make it available to sibling components.
App.jsx (wrapped with ConnectedRouter)
-> contains Layout.jsx
const Layout = function(props) {
return (
<div className="layout" style={layout.base}>
<Header inlineStyles={layout.header} params={props.match.params} />
<Content inlineStyles={layout.content} />
<Footer inlineStyles={layout.footer} />
</div>
);
};
Layout.propTypes = {
match: PropTypes.object
};
export default Layout;
The Content component is where the bulk of my routes begin. When I try to access props.match inside of the Header component, I see this:
// Header.jsx
match: {
isExact: false,
params: {},
path: "/",
url: "/"
}
But when I access the props.match object from the nested component route, I get this:
// Content.jsx > Child > GrandChild
match: {
isExact: true,
params: {orgId: "1", projectId: "11", version: "1.0.0", modelId: "30"},
path: "/orgs/:orgId/projects/:projectId/version/:version/models/:modelId",
url: "/orgs/1/projects/11/version/1.0.0/models/30"
}
This is in the same render cycle.
- Is it expected that the match object is not global to the entire router?
- How do I access the same match object in my Header.jsx file as I have in my Content.jsx?
augnustin, jetpack3331, azakharo, yairEO, lostpebble and 22 more
Metadata
Metadata
Assignees
Labels
No labels