-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inside f-partial-nav
the server-side redirects do not work.
#2560
Comments
A way around the issue is to simply use client-side redirect by rendering an island that uses // routes/submit.tsx
import { Redirect } from "#islands/Redirect.tsx";
...
async POST(req, ctx) {
if (something) {
return ctx.render({redirect: false});
}
else {
return ctx.render({redirect: true});
}
...
export default function Page(props) {
const { redirect } = props.data
if (redirect) {
return (
<Partial name="user_feedback">
<Redirect location="/another-place" />
</Partial>
);
} else {
return (
<Partial name="user_feedback">
Invalid input!
....
} // #islands/Redirect.tsx
import { useEffect } from "preact/hooks";
interface Props {
location: string;
}
export function Redirect(props: Props) {
useEffect(() => {
window.location.href = props.location;
});
return <div></div>;
} This ... works. But it removes some of the benefit of code organization that Partials allows. |
Would it be better if we can hook the partial on the client side and handle exceptions when they occur? I have another issue when attempting to redirect to a different domain for authentication (e.g., using Google accounts). The partial throws an exception related to CORS policy. If we can intercept the partial when it encounters an exception or fails for any reasons, we can simply use |
@cosmoswafer a CORS exception is not related to Partials, it means that you are trying to render an HTML response that does not come from your server. |
lets say I have:
Then in the submit route:
The problem here is that the
301
redirect does not render in the browser because the browser is expecting aPartial
like the one inPage()
, but the/another-place
route is not a Partial's route, it should be full reload.I imagine that the client never knows about the
301
, it only sees the final result (HTML) from the/another-place
resource, and the client treats it as the originally requested resource, so it tries to search for partials in that resource, which there are none in it so nothing "happens" even though it returned an entirely different webpage.Side-note, somewhat amusing, if an
a
anchor tag is outside off-client-nav
then it has no issue with redirects, even if there arePartial
s on the page. However, if ana
anchor ag is insidef-client-nav
, it cannot handle server-side redirects, even if it has not been enabled with anf-partial="/partials/abc"
attribute. I think it would be worth-noting in the docs, although with better phrasing than mine, my pedagogy isn't good right now.The text was updated successfully, but these errors were encountered: