E
E
Elena2022-01-30 09:24:06
React
Elena, 2022-01-30 09:24:06

Nested routing without component in child elements?

I need the path of the child element to be added to the url, but there was no permanent component. So that after clicking on the link "elena" the url would be "users/elena" and go to the Elena() component. Can it be done?

function Users() {
 return (
   <div>
     <Link to="elena"></Link>
     <Link to="oleg"></Link>
   </div>
 );
}

function App() {
 return (
   <Routes>
     <Route path="/users" element={<Users />}>
       <Route path="elena" element={<Elena />} />
       <Route path="oleg" element={<Oleg />} />
     </Route>
   </Routes>
 );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena, 2022-01-30
@Elena0394

It turned out like this:

function App() {
 return (
   <Routes>
     <Route path="/users" >
       <Route path="" element={<Users />} />
       <Route path="elena" element={<Elena />} />
       <Route path="oleg" element={<Oleg />} />
     </Route>
   </Routes>
 );
}

Then the Users() component will not connect with its children

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question