Edit save return to previous page

Is there a way to have the edit save button return you to the previous page instead of the list page?
K
kapa.ai117d ago
Hi @silentnyte. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you can customize the behavior of the save button in the edit form to redirect to a different page instead of the default list page. This can be achieved by using the redirect function from the useForm hook in Refine. Here is an example of how you can use it:
const { onFinish, redirect } = useForm();

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const data = await onFinish(formValues);
redirect("show", data?.data?.id);
};
const { onFinish, redirect } = useForm();

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const data = await onFinish(formValues);
redirect("show", data?.data?.id);
};
In this example, after a successful mutation, the form will redirect to the "show" page. You can replace "show" with any page you want to redirect to. If you want to go back to the previous page, you would need to keep track of that page in your application state or in the URL, and then use that value in the redirect function. For more information, you can refer to the documentation on the useForm hook and its redirect function in the Ant Design (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form#redirect-1) and Mantine (https://refine.dev/docs/ui-integrations/mantine/hooks/use-form#redirect-1) sections of the Refine documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
K
kapa.ai117d ago
<@395261846862561301> kapa.ai is still learning and improving, please let us know how it did by reacting below