3

The Exhibitions element holds a table of 9 exhibitions. On click on an exhibition from the table I want to route to the page of the exhibition (Exhibit1), currently attempting to do so via nested routing.

In the Exhibitions const I have <Link to='/exhibitions/exhibit1'> Exhibit1 </Link> ... <Outlet/>

When clicking on the Link the Exhibit1 component renders under the table.

How can I go about hiding the parent element (Exhibitions), and route to the Exhibit1 page ?

Appreciate all pointers to a workaround.

<Routes>
 <Route path='/' element={<Home/>}/>
 <Route path='/home' element={<Home/>}/>
 <Route path='/aboutUs' element={<AboutUs/>}/>

 <Route path='/exhibitions' element={<Exhibitions/>}> 
  <Route path='exhibit1' element={<Exhibit1/>}/>
 </Route>

 <Route path='/photographers' element={<Photographers/>}/>
 <Route path='/contact' element={<Contact/>}></Route> 
 <Route path='*' element={<Error/>}> </Route> 
</Routes>

1 Answer 1

7

You can use a layout route that renders an Outlet by default and move the Exhibitions component into an index route.

Example:

<Route path='/exhibitions'>
  <Route index element={<Exhibitions />} />        // "/exhibitions"
  <Route path='exhibit1' element={<Exhibit1 />} /> // "/exhibitions/exhibit1"
</Route>

See:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.