def index():
return rx.text("Root Page")
def about():
return rx.text("About Page")
def custom():
return rx.text("Custom Route")
app = rx.App()
app.add_page(index)
app.add_page(about)
app.add_page(custom, route="/custom-route")
index
- The root route, available at /
about
- available at /about
custom
- available at /custom-route
def nested_page():
return rx.text("Nested Page")
app = rx.App()
app.add_page(nested_page, route="/nested/page")
/nested/page
.class State(rx.State):
@rx.var
def post_id(self):
return self.get_query_params().get("pid", "no pid")
def post():
"""A page that updates based on the route."""
return rx.heading(State.post_id)
app = rx.App()
app.add_page(post, route="/post/[pid]")
/post/123
, the page will render with the text 123
.get_query_params()
.class State(rx.State):
@rx.var
def post_id(self):
return self.get_query_params().get("pid", "no pid")
def post():
"""A page that updates based on the route."""
return rx.vstack(
rx.text(State.post_id),
)
app = rx.App()
app.add_page(post, route="/post/[pid]")
The title to be shown in the browser tab
The description as shown in search results
The preview image to be shown when the page is shared on social media
Any additional metadata
def index():
return rx.text("A Beautiful App")
def about():
return rx.text("About Page")
meta = [
{"name": "theme_color", "content": "#FFFFFF"},
{"char_set": "UTF-8"},
{"property": "og:url", "content": "url"},
]
app = rx.App()
app.add_page(
index,
title="My Beautiful App",
description="A beautiful app built with Reflex",
image="/splash.png",
meta=meta,
)
app.add_page(about, title="About Page")
class State(rx.State):
data: Dict[str, Any]
def get_data(self):
# Fetch data
self.data = fetch_data()
def index():
return rx.text("A Beautiful App")
app.add_page(index, on_load=State.get_data)
@rx.page
decorator to add a page.@rx.page(route="/", title="My Beautiful App")
def index():
return rx.text("A Beautiful App")
app.add_page
with the same arguments.