vicious-gold
vicious-gold11mo ago

redirect after create

on succesfull form submit on create or edit, it automatically readirects to list page but i want to additional queryparams to it when redirecting to list
3 Replies
kapa.ai
kapa.ai11mo ago
Hi @Alfaz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Refine provides a way to control the redirection behavior after a successful form submission. By default, it redirects to the list page of the resource. However, you can change this behavior by setting the redirect option in the useForm hook or in the <Refine> component's options. Here's an example of how you can set the redirect option in the useForm hook:
useForm({ redirect: "show" });
useForm({ redirect: "show" });
And here's how you can set it in the <Refine> component's options:
const App = () => (
<Refine
options={{
redirect: {
afterCreate: "show",
afterClone: "edit",
afterEdit: false,
},
}}
/>
);
const App = () => (
<Refine
options={{
redirect: {
afterCreate: "show",
afterClone: "edit",
afterEdit: false,
},
}}
/>
);
In these examples, after a successful create operation, the user will be redirected to the show page, and after a successful clone operation, the user will be redirected to the edit page. If afterEdit is set to false, no redirect will be performed after a successful edit operation. However, the provided information does not include a way to add additional query parameters to the redirect URL. You might need to use a custom function to handle the redirection and add the query parameters manually. For more information, you can check the documentation here (https://refine.dev/docs/data/hooks/use-form#redirect-) and here (https://refine.dev/docs/core/refine-component#redirect). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@763439201353596968> kapa.ai is still learning and improving, please let us know how it did by reacting below
correct-apricot
correct-apricot11mo ago
Hello @Alfaz, first we need to disable automatic redirection
useForm({ redirect:false })
useForm({ redirect:false })
after that you can use onMutationSuccess to manually redirect https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form/#onmutationsuccess for redirection: https://refine.dev/docs/routing/hooks/use-go/

Did you find this page helpful?