Intercepting Parallel Route Modal not being dismissed when going to next page
Answered
Maheśvara posted this in #help-forum
I have a login modal that I've created using an Intercepting Parallel Route.
It works for the most part, however the part that doesn't work is when I use the router to go to the
The following is the code I use to go to that route:
What happens is that the contents of
The directory structure is as shown in the picture and the modal code is as follows:
It works for the most part, however the part that doesn't work is when I use the router to go to the
/dashboard
route.The following is the code I use to go to that route:
const onSubmit: SubmitHandler<TLoginForm> = async (data) => {
try {
const signinResponse = await signIn("credentials", {
email: data.username_email,
password: data.password,
redirect: false,
})
if(signinResponse && !signinResponse.error) {
router.replace("/dashboard")
}
else {
console.error("Error :", signinResponse)
form.setError('root.credentialError', { type:'validate', message: 'Your credentials are incorrect!' })
}
} catch (e) {
if (typeof e === "string") {
console.error(e.toUpperCase())
} else if (e instanceof Error) {
console.error(e.message)
}
}
}
What happens is that the contents of
/dashboard
is successfully rendered, however the login modal is still present.The directory structure is as shown in the picture and the modal code is as follows:
"use client";
import { useCallback } from "react";
import { useRouter } from "next/navigation";
import {
Dialog,
} from "@/components/ui/dialog"
const NativeModal = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
const onDismiss = useCallback(() => {
router.back();
}, [router]);
return (
<Dialog defaultOpen onOpenChange={onDismiss}>
{children}
</Dialog>
);
};
export default NativeModal;
Answered by Maheśvara
The solution I came up with was having the modal be unable to render to the redirect location (dashboard in this case)
3 Replies
Zenaida Dove
one solution might be this:
create a new function for hiding the modal (conditional rendering) and call it before route.replace
create a new function for hiding the modal (conditional rendering) and call it before route.replace
The solution I came up with was having the modal be unable to render to the redirect location (dashboard in this case)
Answer
It's not an elegant solution by any means, but it's just a temporary solution until they fix it properly, because only
router.back()
works properly with it