score:5
Accepted answer
Wrap your header in a <Route>
that always renders. Then you'll have access to everything via props.
class Routes extends React.Component {
render() {
return (
<Router>
<Nav />
<Route render={(props) => {
console.log(props.location)
return (
<header>{customHeader}</header>
)
}} />
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
// Other routes
</Switch>
</Router>
);
}
};
Source: stackoverflow.com
Related Query
- React router get current location on main router component
- React Router v4 get current location
- Can't get proper location state in React Router if location is added in Routes component
- React router get current route outside component
- React router v6 how to get current route in class component
- React Router v4 - How to get current route?
- Get the current path in a react component
- react router get full current path name
- How to get params in component in react router dom v4?
- React Typescript: add location state to react router component
- React Router V4 Get Current Path
- How can i access the current hash location on react router 2?
- how to get current react component name inside custom react hook?
- Is it possible to access the current route component with React Router
- react router - get current route
- React router v4 use declarative Redirect without rendering the current component
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- React router redirects the page but component doesn't get rendered
- React Router v4 redirect to current page and the component disappears
- How to get the current pathname correctly in React Router v6?
- Get params from outside of route component in React Router 6
- React Router - How to pass previous location pathname to current
- React router only show Navigation component if the current path is on any of the valid routes
- Embedded child component doesn't get changed when I click a new one with React Router
- React Router useLocation() location is not followed to the current page
- How can I get a component to render as a parent of protected routes in react router dom?
- Get Location on component mount and pass to App State in Ionic React
- React router pass callback with current route to child component
- How to get location pathname with React Router v5 and Hooks in React v16.13.1?
- React Router: Get location in container component
More Query from same tag
- React - ShowRainBow.state: must be set to an object or null
- how update the value of useEffect() hook on button click
- Slack invite with react and slack api
- MUI Button hover background color and text color
- I want to change variant or background of the clicked button (onClick) only in reactjs. How can i achieve it?
- What is the alternative of makeStyles for Material UI v.5
- i have a problem with displaying my question in seperate page in react
- ReactJS semantic ui Loader: how to toggle active
- How to fix - Module not found: Can't resolve '@babel/runtime/helpers/objectWithoutPropertiesLoose'
- No overload matches this call and Types of parameters '__0' and 'props' are incompatible when passing custom params to library function on typescript
- How should I fix TypeError "property 'props' of undefined"?
- Show popup for only one Marker react map gl
- How to call a state changing helper method in React?
- How to pass types to a functional component in react using redux connect
- Aggrid refresh after state of rowGroupPanelShow changed
- Link Component deosn't redirect page
- react-virtualized table x-scrolling
- How can I implement SSO Authentication with Active Directory in React App?
- Intercepting React Click Events
- JSON format of SVG inside React Component
- How to render a HTML string in React?
- React CSSTransition not animating
- input value not exceeding on typing
- Add event listener for entire document that detects specific key presses
- Behavior of a React component passed as prop
- react not updating child components visually after setstate
- Why is my state not updating after useDispatch
- Dynamically imported modules without relative paths
- React: Bind number input to state (handle intermediate values)
- A good way to check if auth token is valid in a SPA