API Reference





Pages in Reflex allow you to define components for different URLs. This section covers creating pages, handling URL arguments, accessing query parameters, managing page metadata, and handling page load events.

You can create a page by defining a function that returns a component. By default, the function name will be used as the route, but you can also specify a route.

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(custom, route="/custom-route")

In this example we create three pages:

  • index - The root route, available at /
  • about - available at /about
  • /custom - available at /custom-route

You can also use the decorator to add a page."/", title="My Beautiful App")
def index():
    return rx.text("A Beautiful App")

This is equivalent to calling app.add_page with the same arguments.

Index is a special exception where it is available at both / and /index. All other pages are only available at their specified route.

Pages can also have nested routes."/nested/page")
def nested_page():
    return rx.text("Nested Page")

app = rx.App()

This component will be available at /nested/page.

The attribute allows you to obtain the path of the current page from the router data, for dynamic pages this will contain the slug rather than the actual value used to load the page.

To get the actual URL displayed in the browser, use This will contain all query parameters and dynamic path segments.

class State(rx.State):
    def some_method(self):
        current_page_route =
        current_page_url =
        # ... Your logic here ...

In the above example, current_page_route will contain the route pattern (e.g., /posts/[id]), while current_page_url will contain the actual URL (e.g.,

To get the full URL, access the same attributes with full_ prefix.


class State(rx.State):
    def current_url(self) -> str:

In this example, running on localhost should display http://localhost:3000/user/hey/posts/3/

You can use the router.session.client_ip attribute to obtain the IP address of the client associated with the current state.

class State(rx.State):
    def some_method(self):
        client_ip = self.router.session.client_ip
        # ... Your logic here ...

← LibraryDynamic Routing →

Did you find this useful?