combining custom routes and custom layout
It seems when defining custom route that the custom layout is overridden.
I tried with the custom layout in init or in s standalone page with the same result.
I am doing this wrong? is there another of redirecting a route without having the default blue navigation bar? (I actually want to hide it)
import solara
@solara.component
def Layout(children=[]):
# Note that children being passed here for this example will be a Page() element.
route_current, routes_all = solara.use_route()
print(routes_all)
with solara.Column():
# put all buttons in a single row
with solara.Row():
for route in routes_all:
with solara.Link(route):
solara.Button(route.path, color="red" if route_current == route else None)
# under the navigation buttons, we add our children (the single Page())
solara.Column(children=children)
@solara.component
def Page():
solara.Markdown("Page1")
router = solara.use_router() path = router.path parts = path.split("/") solara.Markdown(f"Path = {path!r}, and split up into {parts!r}") # now you can do anything with path or parts. # e.g. # if parts[0] == "docs": # solara.Markdown("You are in the docs section") routes = [ solara.Route(path="/", component=Page, label="home"), solara.Route(path="dev", component=Page, label="home"), ]
router = solara.use_router() path = router.path parts = path.split("/") solara.Markdown(f"Path = {path!r}, and split up into {parts!r}") # now you can do anything with path or parts. # e.g. # if parts[0] == "docs": # solara.Markdown("You are in the docs section") routes = [ solara.Route(path="/", component=Page, label="home"), solara.Route(path="dev", component=Page, label="home"), ]
1 Reply
You almost had it 🙂
I turned it into a nice example: https://py.cafe/maartenbreddels/solara-navigation-example on PyCafe
PyCafe - Solara - Solara Navigation Example
Create & Share Streamlit, Dash and Python Apps Online.