-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
adding a /404 route without app.add_custom_404_page
breaks dynamic routes in prod mode
#4438
Comments
I understand you're encountering an issue where adding a /404 route directly breaks dynamic routes in production, because it bypasses the necessary client-side routing logic. Let me explain what's happening and propose a solution. The root cause is that the
Looking at the codebase, particularly in def wait_for_client_redirect(component) -> Component:
"""Wait for a redirect to occur before rendering a component."""
return cond(
condition=route_not_found,
c1=component,
c2=ClientSideRouting.create(),
) For your specific case, I recommend:
app.add_custom_404_page(
your_404_component,
title="Custom 404",
description="Page not found"
)
from reflex.components.core.client_side_routing import wait_for_client_redirect
app.add_page(
component=wait_for_client_redirect(your_404_component),
route="/404",
title="Custom 404"
) Regarding your suggestion about making
Be careful with:
Let me know if you need any clarification or have questions about implementing either approach. References:
|
Describe the bug
Dynamic routes with a static export depends on being able to trigger client-side routing for non-existant files corresponding to the dynamic route. The static host should serve
/404.html
when the route is not found.However, if the app adds a
/404
page without thewait_for_client_redirect
wrapper applied, then the resulting 404 page will not include the necessary logic to perform the redirect.Instead of having a separate
add_custom_404_page
function, maybe therx.App
should just treat the/404
route specially and ensure that client redirect logic is included. The downside with this approach is there would be no way for the app to opt-out of client side redirection if that were desirable, although i don't know of a practical use case for opting out.Specifics (please complete the following information):
The text was updated successfully, but these errors were encountered: