use_router
Returns the current router object.
def use_router() -> Router:
...
See also Understanding Routing.
use_router
returns the current router object. This is useful to build custom routing.
the router object contains the following properties/methods:
path
- the current pathname (e.g./fruit/banana
)parts
- the current pathname split into parts (e.g.['fruit', 'banana']
)search
- the query parameters string (e.g.color=yellow
).push(path: str)
- navigate to path (e.g.router.push('/fruit/banana')
)
Typical usage:
import solara
@solara.component
def Page():
router = solara.use_router()
def redirect():
router.push(f"/documentation/api/routing/use_route")
solara.Button("Navigate using an event", on_click=redirect)