import solara
# In the docs you can take a look at:
# Understanding Routing: https://solara.dev/documentation/advanced/understanding/routing
# The Link component: https://solara.dev/documentation/components/advanced/link
# Use route and the whole Routing section under API:
# https://solara.dev/documentation/api/routing/use_route
@solara.component
def Page():
solara.Text("Hi! I'm the home route")
# The `Layout` component replaces an `Outlet`. All the children are passed to it so they can be wrapped
@solara.component
def Layout(children=[]):
Navigation()
# Note that we have to pass the children to some component in order for them to render
solara.Column(children=children)
@solara.component
def Navigation():
with solara.Row():
with solara.Link("/"):
solara.Button("Go home")
with solara.Link("/routes/a"):
solara.Button("Go to A")
with solara.Link("/routes/b"):
solara.Button("Go to B")
@solara.component
def PageA():
solara.Text("Hi! I'm page A")
@solara.component
def PageB():
solara.Text("Hi! I'm page B")
# Here we manage routes manually, but this can also be done automatically based on
# file structure, see https://solara.dev/documentation/advanced/understanding/routing
routes = [
solara.Route(
path="/",
component=Page,
layout=Layout, # We only have to add the Layout component once, since all children are wrapped in it
# If you're using file-based routing, Layout components are discovered automatically (based on name)
),
solara.Route(
path="routes",
children=[
solara.Route(path="a", component=PageA),
solara.Route(path="b", component=PageB)
],
),
]