ratty-blush
ratty-blush16mo ago

No List View

Hey hey -- I have an endpoint that I DO NOT want to have a list view. Is there a way to change the default? I only want edit/show/create.
9 Replies
kapa.ai
kapa.ai16mo ago
Hi @itsjamesmurray. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, you can refer to the Refine documentation (https://refine.dev/docs) for more detailed information on how to customize your views. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai16mo ago
<@845761203640205402> kapa.ai is still learning and improving, please let us know how it did by reacting below
ratty-blush
ratty-blushOP16mo ago
@kapa.ai is there a way to change the default page for a resource from list to something like show?
kapa.ai
kapa.ai16mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, you can customize the default page for a resource in Refine. By default, the index route is defined with the NavigateToResource component which redirects the user to the list page of the first defined resource. However, you can override this behavior by defining your own paths for the resource actions. For example, you can define the show action's path as /categories/:id/details which will override the default path. When components are used to define the resource actions, default paths will be used. You can override the default paths by assigning an object with component and path properties to the action properties. Here's an example of how you can define the paths for your resource:
const App: React.FC = () => {
return (
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
show: "/samples/show/:id",
create: "/samples/create",
edit: "/samples/edit/:id",
},
]}
>
<Routes>
<Route path="/samples" element={<HeadlessInferencer />} />
<Route
path="/samples/create"
element={<HeadlessInferencer />}
/>
{/** highlight-next-line */}
<Route
path="/samples/show/:id"
element={<HeadlessInferencer />}
/>
<Route
path="/samples/edit/:id"
element={<HeadlessInferencer />}
/>
<Route path="*" element={<div>Not Found</div>} />
</Routes>
</Refine>
</BrowserRouter>
);
};
const App: React.FC = () => {
return (
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
show: "/samples/show/:id",
create: "/samples/create",
edit: "/samples/edit/:id",
},
]}
>
<Routes>
<Route path="/samples" element={<HeadlessInferencer />} />
<Route
path="/samples/create"
element={<HeadlessInferencer />}
/>
{/** highlight-next-line */}
<Route
path="/samples/show/:id"
element={<HeadlessInferencer />}
/>
<Route
path="/samples/edit/:id"
element={<HeadlessInferencer />}
/>
<Route path="*" element={<div>Not Found</div>} />
</Routes>
</Refine>
</BrowserRouter>
);
};
In this example, the show action's path is defined as /samples/show/:id, which will be the default path for the show action of the samples resource. For more information, you can refer to the Refine documentation (https://refine.dev/docs/packages/documentation/routers/react-router-v6). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai16mo ago
<@845761203640205402> kapa.ai is still learning and improving, please let us know how it did by reacting below
ratty-blush
ratty-blushOP16mo ago
@kapa.ai is it possible to have NO list action path?
kapa.ai
kapa.ai16mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, it is possible to have no list action path for a resource in Refine. You can simply omit the list property when defining your resources. However, please note that this might affect the navigation of your application, as the list action is typically used for displaying a list of resources. Here's an example of how you can define a resource without a list action:
resources={[
{
name: "products",
show: "/:tenantId/products/:id",
edit: "/:tenantId/products/:id/edit",
create: "/:tenantId/products/create",
}
]}
resources={[
{
name: "products",
show: "/:tenantId/products/:id",
edit: "/:tenantId/products/:id/edit",
create: "/:tenantId/products/create",
}
]}
In this example, the products resource has show, edit, and create actions, but no list action. Please refer to the Refine documentation (https://refine.dev/docs/api-reference/core/components/refine-config) for more details on how to configure your resources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai16mo ago
<@845761203640205402> kapa.ai is still learning and improving, please let us know how it did by reacting below
rival-black
rival-black16mo ago
Hey @itsjamesmurray, It isn't required to add the list prop to your resource definetion. However, if you don't, you will not see a link to the resource in <Sider />. Therefore, you can define list using the route path you want to redirect to. Or you can swizzle and customize the Sider.