wise-white
wise-white2y ago

Redirect to a different resource after create

Hello, I have this 2 resources TemplateGroup and Template. Every Template belongs to a TemplateGroup. When I create (or edit) a Template, i want to be redirected on the Show page of the right TemplateGroup (with the same id sent to the server)... Is there a quick way to do it, or i have to set redirect: false and use an effect on the query object to trigger the redirect? It would be cool to set something like redirect : { resource: "template", action: "show", id: 123 }
3 Replies
absent-sapphire
absent-sapphire2y ago
Hey @kino90 The useNavigation hook makes this easy. You can see the usage here. https://refine.dev/docs/api-reference/core/hooks/navigation/useNavigation/#usage
useNavigation | refine
refine uses routerProvider and comes with all redirects out of the box. It allows you to manage your routing operations in refine. Using this hook, you can manage all the routing operations of your application very easily.
absent-sapphire
absent-sapphire2y ago
Also use it with onSuccess
const { edit } = useNavigation();
const onFinish = (values: any) => {
mutate(
{
.....
{
onSuccess: () => {
return edit("post", "1");
},
}
);
};
const { edit } = useNavigation();
const onFinish = (values: any) => {
mutate(
{
.....
{
onSuccess: () => {
return edit("post", "1");
},
}
);
};
wise-white
wise-white2y ago
worked, thank you! It's incredible how flexible is Refine! refine lovin' it