路由到嵌套路径v6 reactjs时如何隐藏父组件?

发布于 2025-01-27 15:22:47 字数 817 浏览 1 评论 0原文

展览元素拥有9个展览的桌子。单击桌子上的展览,我想路由到展览页面(展览1),目前试图通过嵌套路由进行。

在展览中,const i具有<链接到='/doarbients/doartit1'>展览1</link> ...< utlet/>

在单击链接时,exhibit1组件在表下方呈现。

我该如何隐藏父元素(展览)和通往展览1页的路线?

感谢所有的解决方法。

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2025-02-03 15:22:47

您可以使用一个布局路由,该路由默认情况下呈现otret,然后将展览组件移动到索引路由中。

示例:

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

请参阅:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文