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,
)
| 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): |