How to hide the parent component data when going nested in the component?

Puru Chaudhary

I am learning React and trying to build a project which is a simple house listing website. Here I am navigating to the top menu "List Room" which is showing in the image and then when the user clicks on the next button I want to go to the List Room 2 component which is also happening but the data of the parent listroom is showing how can I hide this?enter image description here

<Routes>
<Route path = "/" element = { <MainMenu />}>
 <Route index element = { Home />} />
 <Route path = "/listrooms" element = { <ListRooms />}>
    <Route path = "listrooms2" element = { <ListRooms2 />} />
 </Route>
 <Route path = "/login" element = { <Login />} />
 <Route path = "*" element = { <ErrorPage />} />
</Route>
</Routes> 
 
Drew Reese

If you want ListRooms2 to be rendered on the nested "/listrooms/listrooms2" path and not render ListRooms at the same time then move ListRooms to its own index route to only be rendered when the path is "/listrooms".

<Routes>
  <Route path="/" element={<MainMenu />}>
    <Route index element={<Home />} />
    <Route path="/listrooms">
      <Route index element={<ListRooms />} />
      <Route path="listrooms2" element={<ListRooms2 />} />
    </Route>
    <Route path="/login" element={<Login />} />
    <Route path="*" element={<ErrorPage />} />
  </Route>
</Routes> 

Alternatively you could unnest the routes, e.g. render each individually, using the complete absolute path.

<Routes>
  <Route path="/" element={<MainMenu />}>
    <Route index element={<Home />} />
    <Route path="/listrooms" element={<ListRooms />} />
    <Route path="/listrooms/listrooms2" element={<ListRooms2 />} />
    <Route path="/login" element={<Login />} />
    <Route path="*" element={<ErrorPage />} />
  </Route>
</Routes> 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to hide a parent component when switching to a child component

Nested React Router : hide parent component on showing nested child component

How to hide a parent component from a child component?

How to show/hide component in parent component via a button in a child component when using a map of buttons?

How can I set the data on this component when inside a parent component?

Vue nested data: child component not hidden when parent node is deleted

How to pass data from child component to parent component when button clicked on parent component

How can I update data from parent component when I click child component on the vue component?

Angular: How do I keep component state in nested component tree when parent list is replaced

Pass data from Parent Component to nested Child Component in Angular

How to show and hide a Modal in child component from Parent component?

How to style a nested component from its parent component in Vuejs?

How to update parent component view when data is fetched from child component?

Data lost on vue dynamic component when back to parent component

When list rendering a component, nested component data doesn't update

How to use child component data in parent component? How to make a binding?

how to make child component update when form in parent component submit

How to re render parent component when anything changes in Child Component?

How to access data in a child react component from a parent react component

How to send data from a child component to parent component in React

How to pass async data to child component from parent component?

How to send data from parent component to child component in AngularJs

How to pass data from Child to Parent, if Child component dynamic component

How to send data from child component to parent component in reactjs

Nested Child Component not passing Info to Parent Component

How to change parent data from a child component?

How to pass data from child component to parent

How to pass data from mapStateToProps to parent component?

How to acces to parent data in child component