A view router for Textual projects
Project description
Textual Router
A view router for Textual inspired by Solid-Router.
Usage
Create Views from Static widgets.
Use the Router object in your App's compose() and provide links and their Views:
yield Router(
[
Route(path="link_to_view_a", view=ViewA()),
Route(path="link_to_view_b", view=ViewB()),
]
)
Within in your View, use RouterLinks to navigate to other views.
yield RouterLink(path="link_to_view_b",label="ViewB")
To use links outside the Router, you can use its "route_to" method:
async def action_main_menu(self) -> None:
cast(RouterType, self.query_one("#router")).route_to("link_to_view_a")
The Router's identifier defaults to "router", but can be customized:
yield Router(
routes=[
Route(path="link_to_view_a", view=ViewA()),
Route(path="link_to_view_b", view=ViewB()),
],
identifier="app_router"
)
Full Example
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, Static
from textual_router import Route, Router, RouterLink
class Home(Static):
def compose(self):
yield RouterLink(path="about", label="About")
class About(Static):
def compose(self):
yield RouterLink(path="home", label="Home")
class BasicApp(App):
TITLE = "Basic app"
def compose(self) -> ComposeResult:
yield Header()
yield Router(
[
Route(path="home", view=Home()),
Route(path="about", view=About()),
]
)
yield Footer()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file textual_router-0.2.3.tar.gz.
File metadata
- Download URL: textual_router-0.2.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5bf614d1f362d6ee4f337663e29402c734f5fb66a12eaa561714d570f4c261
|
|
| MD5 |
1522afaab4078672b07b8b106f03f899
|
|
| BLAKE2b-256 |
10725d81707bd8037a9c6ee8d52a4edb07ccf816d9d89984497b94501f934a89
|
File details
Details for the file textual_router-0.2.3-py3-none-any.whl.
File metadata
- Download URL: textual_router-0.2.3-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d402539b0bc98b65a4d7fa6cd980c2804fb647350fa683043ce3b32f18dd126
|
|
| MD5 |
97d6cb2805dd63e3f8c6bb0583755f79
|
|
| BLAKE2b-256 |
5566798f502a4afa1449af010673f7b1e401197de2c96ab07f1a6378ddc0962f
|