MCPcopy
hub / github.com/reflex-dev/reflex / add_page

Method add_page

reflex/app.py:864–974  ·  view source on GitHub ↗

Add a page to the app. If the component is a callable, by default the route is the name of the function. Otherwise, a route must be provided. Args: component: The component to display at the page. route: The route to display the component at.

(
        self,
        component: Component | ComponentCallable | None = None,
        route: str | None = None,
        title: str | Var | None = None,
        description: str | Var | None = None,
        image: str = constants.DefaultPage.IMAGE,
        on_load: EventType[()] | None = None,
        meta: Sequence[Mapping[str, Any] | Component] = constants.DefaultPage.META_LIST,
        context: dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

862 return into_component(component)
863
864 def add_page(
865 self,
866 component: Component | ComponentCallable | None = None,
867 route: str | None = None,
868 title: str | Var | None = None,
869 description: str | Var | None = None,
870 image: str = constants.DefaultPage.IMAGE,
871 on_load: EventType[()] | None = None,
872 meta: Sequence[Mapping[str, Any] | Component] = constants.DefaultPage.META_LIST,
873 context: dict[str, Any] | None = None,
874 ):
875 """Add a page to the app.
876
877 If the component is a callable, by default the route is the name of the
878 function. Otherwise, a route must be provided.
879
880 Args:
881 component: The component to display at the page.
882 route: The route to display the component at.
883 title: The title of the page.
884 description: The description of the page.
885 image: The image to display on the page.
886 on_load: The event handler(s) that will be called each time the page load.
887 meta: The metadata of the page.
888 context: Values passed to page for custom page-specific logic.
889
890 Raises:
891 PageValueError: When the component is not set for a non-404 page.
892 RouteValueError: When the specified route name already exists.
893 """
894 # If the route is not set, get it from the callable.
895 if route is None:
896 if not isinstance(component, Callable):
897 msg = "Route must be set if component is not a callable."
898 raise exceptions.RouteValueError(msg)
899 # Format the route.
900 route = format.format_route(format.to_kebab_case(component.__name__))
901 else:
902 route = format.format_route(route)
903
904 if route == constants.Page404.SLUG:
905 if component is None:
906 from reflex_components_core.el.elements import span
907
908 component = span("404: Page not found")
909 component = self._generate_component(component)
910 title = title or constants.Page404.TITLE
911 description = description or constants.Page404.DESCRIPTION
912 image = image or constants.Page404.IMAGE
913 else:
914 if component is None:
915 msg = "Component must be set for a non-404 page."
916 raise exceptions.PageValueError(msg)
917
918 # Check if the route given is valid
919 verify_route_validity(route)
920
921 if isinstance(component, Callable):

Callers 15

DeployUrlSampleFunction · 0.95
UploadFileFunction · 0.95
TelemetryCompileAppFunction · 0.95
LoginSampleFunction · 0.95
ComputedVarsFunction · 0.95
ConnectionBannerFunction · 0.95
TailwindAppFunction · 0.95
BackgroundTaskFunction · 0.95
HybridPropertiesFunction · 0.95
TestEventActionFunction · 0.95
StateInheritanceFunction · 0.95
LinkedStateAppFunction · 0.95

Calls 7

_generate_componentMethod · 0.95
merged_withMethod · 0.95
verify_route_validityFunction · 0.90
get_route_argsFunction · 0.90
UnevaluatedPageClass · 0.85
setup_dynamic_argsMethod · 0.80

Tested by 15

DeployUrlSampleFunction · 0.76
UploadFileFunction · 0.76
TelemetryCompileAppFunction · 0.76
LoginSampleFunction · 0.76
ComputedVarsFunction · 0.76
ConnectionBannerFunction · 0.76
TailwindAppFunction · 0.76
BackgroundTaskFunction · 0.76
HybridPropertiesFunction · 0.76
TestEventActionFunction · 0.76
StateInheritanceFunction · 0.76
LinkedStateAppFunction · 0.76