score:1
You can use another layout component to wrap the HomePage
and VersionPage
components so they are rendered with the BreadcrumbHeader
.
<div className="App">
<Routes>
<Route
element={(
<>
<Header />
<Outlet />
</>
)}
>
<Route
element={(
<>
<BreadcrumbHeader />
<Outlet />
</>
)}
>
<Route path="/" element={<HomePage />} />
<Route path="/version/:Id" element={<VersionPage />} />
</Route>
<Route path="*" element={<NotFoundPage />} />
</Route>
</Routes>
</div>
score:1
2 ways :
useLocation and compare the location.path on your BreadCrumb component, something like =>
const location = useLocation() render( <> {location.path === 'toto' && } </> )
If you have just 2 or 3 routes, it's "ok", if you want more...
nested routes !! much better practice =>
<Route path="/" element={}> <Route path="/version/:id" element={} /> // other routes with breadC
You create a component ContainerWithBreath, you put the component BreadC here, don't forget to use (see the doc, it's like says "put the nested component here").
see doc part "nesting routes" for more explain
// Edit So in fact, nesting routes is a route with subRoutes, for example : /user is routes /user/profil is subRoutes
So for that, you use Route component that take path='/user' and render a component like container with your component similar for each of subRoutes. Children of this route, you put new component route, with the sub page.
In your case
<Route path="/" element={<ContainerWithB />} >
<Route path="/version/:Id" element={<VersionPage />} />
<Route index element={<Home />} />
</Route>
First line render container (you need to place on the render of ContainerWithB to display the nested route element . Second line your VersionPage Third line your Home page for '/'
Better ?
Source: stackoverflow.com
Related Query
- Render component on certain paths only react router v6
- Render Same Component With Multiple Paths React Router Dom
- React Router Dom, render a component only for some routes
- React useState hook - I want to render certain component when only press submit button not when onChange
- react router how can I render only the component in his route whiout the others?
- react router difference between component and render
- React Router V6 - Error: useRoutes() may be used only in the context of a <Router> component
- Using React Router and Webpack 2 how to require external libraries only on certain routes?
- How to pass the match when using render in Route component from react router (v4)
- Render async component in React Router v4
- onEnter Transitions with React Router and Redux Simple Router Dont Render New Route's Component
- Does React render the WHOLE component if only one part of the component changed?
- React Router V4 allow only certain parameters in URL
- Only render a react component when I on submit from a form
- React Router V4: How to render a modal in the same screen changing only the url and then with that url, be able to rebuild the whole screen
- React router 4 `Link` component only changing the url and not updating the route
- How to render component only once in React Native
- React Router V6 - useNavigate() may be used only in the context of a <Router> component
- React router v4 render component inside element
- React router dom redirect problem. Changes url, does not render component
- React Router does not render Component
- react router doesn't render component
- React Router master-detail: children component don't render new view until page refresh
- React router render component on same page
- How to 1). put a div , 2). render a component without Route inside <Routes> with React Router in v6 React?
- TSparticles React render particles only inside component
- How to use React Router to replace a Component in render method?
- Using if statement to determine if a Firebase User can access certain React Router paths
- How to render React (with Redux) component only when props are received?
- React Router with different paths on same component: does not re-initialize component (useEffect [] not called)
More Query from same tag
- How to make Bootstrap cards (using ReactJS) move to new line after three have been rendered?
- How to get country, state and city name globally from google auto complete service
- firebase google authentication with token
- Function components cannot be given refs. Attempts to access this ref will fail
- How to parse mixed content into React components?
- Jest testing, sessionStorage undefined
- Reactjs:Is it possible to use Parent component property from another Parent's child component
- How to reset input value after a button click that is not inside of a form in React.js
- ReactJS Dialog with close button
- React.js how to properly instantiate child component in parent class
- How to optimize webpack/es6 overhead?
- Fail creating a SubMenu in a component with antd
- How to write unit test redux connected components in next.js app with Jest end Enzyme
- Using redux to take a time on a stopwatch and put it into a database
- Conditional rendering of useContext
- React Component Ignoring the <h1> tag
- Gulping ReactJS based on environmental variables?
- react how to stop useffect causing components to rerender
- How to stop infinite loop when setting initial state from API with useReducer (React Hooks)
- In React is there a more standard way than this of referring to the outer class from within a map?
- Remove duplicate JSX elements | React Strapi graphql
- Mocking functional component in jest throws "Invalid variable access" error
- How can I selectively delete dynamically added input fields in React?
- Can actions dispatched using mapDispatchToProps be accessed in any component or just in the component mapDispatchToProps is written
- There is no result with react
- Next.js: How to dynamically import external client-side only React components into Server-Side-Rendering apps developed?
- how to get list of all registered synthetic event handlers/listeners for a React Component?
- Deploy ReactJs Azure Static Web App based on Azure DevOps git repo via Azure CLI
- reactjs conditional component methods based on configuration object
- How can I pass a URL querystring variable dynamically to a composed graphql query in react?