diff --git a/docs/app/reflex_docs/templates/docpage/docpage.py b/docs/app/reflex_docs/templates/docpage/docpage.py index 21299a99d84..153529a8ed4 100644 --- a/docs/app/reflex_docs/templates/docpage/docpage.py +++ b/docs/app/reflex_docs/templates/docpage/docpage.py @@ -89,13 +89,24 @@ def handle_submit(self, form_data: dict): pass -def footer_link(text: str, href: str): - return rx.link( - text, - class_name="font-small text-secondary-9 hover:!text-secondary-11 transition-color", - href=href, - underline="none", +def footer_link(text: str, href: str, *, root_site: bool = False) -> rx.Component: + """Create a footer link, optionally bypassing the docs router basename. + + Args: + text: The visible link label. + href: The link destination. + root_site: Whether the destination is outside the docs router basename. + + Returns: + The styled footer link. + """ + class_name = ( + "font-small text-secondary-9 hover:!text-secondary-11 " + "transition-color no-underline" ) + if root_site: + return rx.el.elements.a(text, href=href, class_name=class_name) + return rx.link(text, href=href, class_name=class_name, underline="none") def footer_link_flex(heading: str, links): @@ -360,7 +371,7 @@ def docpage_footer(path: rx.Var[str]) -> rx.Component: "Links", [ footer_link("Home", "/"), - footer_link("Blog", "/blog"), + footer_link("Blog", "/blog/", root_site=True), footer_link("Changelog", "/changelog/"), ], ), @@ -376,7 +387,7 @@ def docpage_footer(path: rx.Var[str]) -> rx.Component: footer_link_flex( "Resources", [ - footer_link("FAQ", "/faq/"), + footer_link("FAQ", "/faq/", root_site=True), footer_link("Roadmap", ROADMAP_URL), footer_link("Forum", FORUM_URL), ], diff --git a/docs/app/tests/test_routes.py b/docs/app/tests/test_routes.py index 3a6dc3a99fb..b6fe3fdeba0 100644 --- a/docs/app/tests/test_routes.py +++ b/docs/app/tests/test_routes.py @@ -3,6 +3,7 @@ from collections import Counter import pytest +import reflex as rx @pytest.fixture @@ -62,3 +63,27 @@ def test_docs_route_descriptions_fit_search_snippet_length(routes_fixture): } assert overlong == {} + + +@pytest.mark.parametrize( + ("label", "href"), + [("Blog", "/blog/"), ("FAQ", "/faq/")], +) +def test_docpage_footer_uses_root_site_anchors(label: str, href: str): + """Root-site footer links should not inherit the /docs router basename.""" + from reflex_docs.templates.docpage.docpage import docpage_footer + + rendered = docpage_footer.__wrapped__(rx.Var.create("/test")).render() + + def find_link(node: dict) -> dict | None: + if any(child.get("contents") == f'"{label}"' for child in node["children"]): + return node + for child in node["children"]: + if "children" in child and (link := find_link(child)) is not None: + return link + return None + + link = find_link(rendered) + assert link is not None + assert link["name"] == '"a"' + assert f'href:"{href}"' in link["props"]