在这种情况下,什么是"index=true“?我为什么要使用index=true ??(反应性路由器-dom v6 useRoutes)
{
path: 'dashboard',
element: (
<AuthGuard>
<DashboardLayout />
</AuthGuard>
),
children: [
{
path: 'e-commerce',
children: [
{ element: <Navigate to="/dashboard/e-commerce/shop" replace />, index: true },
{ path: 'shop', element: <EcommerceShop /> },
{ path: 'product/', element: <EcommerceProductDetails /> },
{ path: 'list', element: <EcommerceProductList /> },
],
},发布于 2022-05-04 13:21:06
index告诉react-router,当您在route的索引处时,它应该呈现提供的element。
在本例中,它将在<Navigate to="/dashboard/e-commerce/shop" replace />路由上呈现/dashboard/e-commerce。在本例中,这将确保用户重定向到/dashboard/e-commerce/shop,如果用户在此路由上意外着陆的话。
通过一个例子,index路由背后的概念变得更加清晰:
<Route path="albums" element={<BaseLayout />}>
<Route index element={<AlbumsList />} />
<Route path=":id" element={<AlbumDetail />} />
<Route path="new" element={<NewAlbumForm />} />
</Route>在/albums,它将呈现:
<BaseLayout>
<AlbumsList />
</BaseLayout>在/albums/some-unique-album-id,它将呈现:
<BaseLayout>
<AlbumDetail />
</BaseLayout>在/albums/new,它将呈现:
<BaseLayout>
<NewAlbumForm />
</BaseLayout>https://stackoverflow.com/questions/72113415
复制相似问题