Argument of type '"replace"' is not assignable to parameter of type 'RedirectType | undefined'
Answered
Argentine ant posted this in #help-forum
Argentine antOP
Gotta say this one has got me a little bit stumped, using Next.js 13.4.6 and attempting to do shallow routing in a server action but
is throwing the above error. Am I missing something? Here's the Next.js types as declared:
redirect(`/login?status=${encodedString}`, "replace")is throwing the above error. Am I missing something? Here's the Next.js types as declared:
export declare function redirect(url: string, type?: RedirectType): never;export declare enum RedirectType {
push = "push",
replace = "replace"
}Answered by joulev
import { RedirectType } from "next/dist/client/components/redirect";
import { redirect } from "next/navigation";
redirect("/", RedirectType.replace);this is an undocumented feature though so use at your own risk
9 Replies
Argentine antOP
also
redirect(`/login?status=${encodedString}`, replace) throws the error Cannot find name 'replace'. Did you mean 'Replace'?ts(2552)@Argentine ant Gotta say this one has got me a little bit stumped, using Next.js 13.4.6 and attempting to do shallow routing in a server action but
redirect(`/login?status=${encodedString}`, "replace")
is throwing the above error. Am I missing something? Here's the Next.js types as declared:
export declare function redirect(url: string, type?: RedirectType): never;
export declare enum RedirectType {
push = "push",
replace = "replace"
}
import { RedirectType } from "next/dist/client/components/redirect";
import { redirect } from "next/navigation";
redirect("/", RedirectType.replace);this is an undocumented feature though so use at your own risk
Answer
btw this isn't shallow routing
this is just similar to router.replace compared to router.push
Argentine antOP
Ahh makes sense
shallow routing option in the works by chance?
that one i don't know
Argentine antOP
that was going to be my perfect trick to trigger toast notifications client-side while rendering the entire rest of the page server-side
still works but with a janky page refresh