score:2
Accepted answer
function App() {
return (
<Router>
<div className="App">
<Routes>
<Route
element={(
<>
<NavBar />
<Outlet />
</>
)}
>
<Route path="/componenta" element={<ComponentA />} />
<Route path="/componentb" element={<ComponentB />} />
</Route>
... other routes without navbar
</Routes>
</div>
</Router>
);
}
score:2
<NavBar />
<Routes>
<Route exact path="/componenta" element={<ComponentA />} />
<Route exact path="/componentb" element={<ComponentB />} />
</Routes>
Source: stackoverflow.com
Related Query
- React route: NavBar always on top while navigating around the components
- React router render prop route always re-renders components
- Abort request while navigating away from the component in React
- React + Express.js server should always return the same index.html file, no matter what url route
- How to Bind different react components with the same react-router route depending on redux state?
- React Router - route using MemoryRouter and Router together (Some links use memory while others change the url)
- What's the correct way to render React components with different styles such as Navbar using React Router 6v?
- React Router: How to render different components with the same route conditionally
- Sharing React components between projects while keeping the source code in one of them
- react router v6 - modal as nested route - cannot render outlet (trying to render modal on top of the existing page)
- Only rerender the affected child in list of components while state resides in parent React
- Route stays the same with links platform/:id in Navbar dropdown item React react-bootstrap
- Components not having the expected props, while React and Redux Dev Tools are having the expected States and Props
- Navigate to anther component while on-form submit and passing the data to navigating component react Js
- React Redux - Keep the same URL while navigating to different pages
- One of my component in React is not loading while the rest of the components load fine
- React router v6 - Navigating from parent route to nested route without showing the parent route
- React Router: State empty when navigating to route via the browser address bar
- remove the navbar and style in my new page redirect. React js Route
- Placing components on the right and around other items in React problem
- How to set the DefaultRoute to another Route in React Router
- How to show a loading indicator in React Redux app while fetching the data?
- Rendering React components with promises inside the render method
- Is there a way to render multiple React components in the React.render() function?
- Error while creating new React app ("You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)")
- having multiple instance of same reusable redux react components on the same page/route
- Re-render component when navigating the stack with React Navigation
- What is the significance of "{" "}" braces around this react library code?
- How to check when the react components get rendered or rerendered
- React hooks: How to write variables in functional components that in class components were initialized in the constructor
More Query from same tag
- How to avoid letting an async thunk that is no longer useful (the app is not expecting it anymore) from being able to update the state?
- Collect checkbox values as an array React
- Changing state of a child element from App component
- Update Timestamp in Firestore with React
- How to open the accordion for each item when click on icon?
- How to save a copy of a state before it changes when using useState?
- Hook error using Truffle React box (transforming the App.js from Class component to Functional component)
- How to pass state to another component using useHistory?
- React PropType with ESLint
- How to handle keyboard events on a document level in ReacJS
- Storing routes in a file and importing into App.js
- it's possible to set timer on reducer state? React + Redux
- Is It Possible To Get The Key From The React Route To Be Pass In Component?
- React server is not running through npm start
- Call next on Flicking Carousel in React
- How to highlight navbar links on page scroll in React
- How to import modules from a folder outside node modules in next js
- Are the properties in {...rest} being passed down to {routeProps} when passing props in react-router?
- React router transitionTo, .substring is not a function
- In create-react-app, my component won't compile because a static arrow function comes back undefined
- TS2339: Property 'id' does not exist on type '{}'
- Redux mapStateToProps is not working in my mapbox map
- Unable to export multiple cloud functions
- Why does my onClick handler not log out the latest version of state and how can I troubleshoot this?
- 'outerMap' is not defined no-undef
- I have a chart but it is not updating the chart with react chart-js-2
- material UI datagrid vertical scroll bar
- Problem to access data from a firebase project in a react application
- React useEffect(), fetch data with React Hooks and set the formik form
- React Native View and Flex: 1 not working as expected