score:0
Accepted answer
You need like this (taken from react-router-dom documentation):
export default function App() {
return (
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/users">Users</Link>
</li>
</ul>
</nav>
{/* A <Switch> looks through its children <Route>s and
renders the first one that matches the current URL. */}
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/users">
<Users />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
</Router>
);
}
Source: stackoverflow.com
Related Query
- React Router - Nested Components will not Render
- React Router will not render Route component unless page is refreshed
- Render multiple components in React Router
- React - component will not render in foreach loop?
- React Router v4 not rendering components
- Unsafe legacy lifecycles will not be called for components using new component APIs. React v16.3
- React router render prop route always re-renders components
- Is there a clean way to conditionally load and render different components for the same React Router route?
- React - will not re render on state change
- React router dom redirect problem. Changes url, does not render component
- React Router does not render Component
- Routes/Redirects do not render in a React Router 4 & Redux Authorization
- How to fix Type not assignable to LibraryManagedAttributes for react router render prop
- React Router V4 - Route between components and not entire page
- Using React Router to load components You should not use <Link> outside a <Router>
- React Router render components with /:username or /component/
- React data components table does not render HTML
- React Router not displaying my components
- React will not render to screen
- react router not rendering components at route
- React Mobx - Change store from other store not render observer components
- MobX, React Router v4, Route using render function not observing and re-rendering when store changes
- React router render not getting props
- React Router will not take array as prop for a component
- React router dom changes url, does not render component
- React router does not render route when URL accessed directly
- React router - page does not render until I do a browser refresh
- React router not rendering JSX components
- React Router returns child components and not parent component
- React router NavLink activeClassName does not work with redux and styled components
More Query from same tag
- how can I use nested css template literals in styled-components, emotion
- React stateless component with controlled form Elements?
- Conditional in jsx return statement
- i create my own npm package and publish it but when i trying to use it, it gives me an error
- Reset React state after component animation ends?
- Correct use of arrow functions in React
- Slate editor active state always false using isBlockActive from examples
- Element type is invalid when creating DragDropContext
- How to map 3 different objects on a table
- Element type is invalid error using react-native and react navigation
- Draft.js - How to trim contents
- "Unknown word" error showing after adding postcss-loader
- which React component should i use with parameters?
- Two svgo-loader conflict
- How to sync components sharing state hook in React
- How do I solve this TypeError: props.onSubmit is not a function?
- How do I properly call multiple functions in componentDidMount?
- How can I build a React app with Webpack and import an assets folder?
- How to dynamically add a CSS class to a div in a component
- React - New Context API not working with Class.contextType, but works with Context.Consumer
- React JS infinite loop on redux sagas
- Adding custom CSS styling to Material UI KeyboardDatePicker
- Table inside table in react
- array of objects always return 0 ,although it has more than one object inside
- How do I call/execute a function from another component in react native?
- React access DOM element instead of object thru refs
- How to calculate mouse position relative to drawing area when it hovers over element being drawn
- How can I make this element class change on scroll in React?
- Axios with React gives 200 (304 in network tab), but gives junk HTML response
- How to do basic validation on React Boostrap 5 input