fair-rose
fair-rose•2w ago

After saving record, then back to previous page instead of list

I would like to go back to previous page after saving record. Even, I specified the navigation path, the path goes to that resource list page. Is it possible to set it to back to previous page instead of list?
2 Replies
kapa.ai
kapa.ai•2w ago
Hi @vtong 🙋♂. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to go back to the previous page after saving a record instead of always redirecting to the list page. You can achieve this by customizing the redirect behavior in your form logic. A common approach is to use the redirect: false option in the useForm hook, which prevents the default redirection after form submission. Then, you can manually call the goBack function (from useNavigation or useBack) in the onMutationSuccess callback to navigate to the previous page in the browser history. Here’s an example pattern based on the knowledge sources:
const { goBack } = useNavigation();
const { redirect } = useForm({
redirect: false,
onMutationSuccess: () => {
goBack();
}
});
const { goBack } = useNavigation();
const { redirect } = useForm({
redirect: false,
onMutationSuccess: () => {
goBack();
}
});
This setup ensures that after a successful save, the user is taken back to the previous page, preserving their navigation context, rather than being sent to the resource list page by default. This approach is also recommended in community discussions for cases where you want to maintain filters, sorting, or pagination state on the list page when returning from an edit or create form Preserve query params when navigating from list to edit and back. If the history stack is empty or you want a fallback, you can use the redirect function to go to a specific page as needed. Note: Make sure you set redirect: false in your useForm configuration to prevent the default redirect behavior useForm redirect parameter. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai•2w ago
<@1172845458167709838> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?