janelkit-router
Navigation between screens: page stacks that keep their state, parallel sections, results with await, questions before leaving and transitions.
janelkit-router Navigation between screens: page stacks that keep their state, parallel sections, results with await and transitions. pip install janelkit-routerWhat it adds
A desktop application with more than one screen needs to move between them. janelkit-router gives you two tools, both made of your ordinary .janel components with props and events; there are no URLs. A page stack models a journey with Back: a list, then a detail, then back to the same list as you left it. Sections model separate destinations, such as a sidebar with Projects and People, each keeping its own journey.
A second operating-system window is not navigation: open_window, in the core, opens one.
| Tool | Shows | Keeps |
|---|---|---|
| pages(...) + <Pages> | The top page of a stack | The pages underneath, alive, for Back. |
| sections(...) + <Sections> | One destination at a time | Every destination’s whole stack. |
| open_window(...) (core) | Another window | Its own component, until it is closed. |
Learn moreWindows and screens ↗
In one minute
Install it next to janelkit with pip install janelkit-router. pages(First) creates a stack during setup, starting with the component First, and <Pages stack={nav} /> shows its top page and takes the free space. Pages and Sections are elements of this package: import them in the script, like a component, and write them with a capital letter.
A page gets its stack with navigation() during its own setup, without receiving it as a prop. push shows a new page on top; the page underneath stays alive, so when the user comes back with pop, it is exactly as it was left.
<script lang="python">
from janelkit_router import pages, Pages
from pages.Home import Home
nav = pages(Home)
</script>
<window title="Pages" width={420} height={260}>
<Pages stack={nav} />
</window>Copy<script lang="python">
from janelkit import state
from janelkit_router import navigation
from pages.Detail import Detail
nav = navigation()
draft = state("")
</script>
<column padding={24} gap={12}>
<textfield bind:value={draft} placeholder="Type something" label="Draft" />
<button on:click={nav.push(Detail)}>Open detail</button>
</column>Copy<script lang="python">
from janelkit_router import navigation
nav = navigation()
</script>
<column padding={24} gap={12}>
<text>Detail page</text>
<button on:click={nav.pop()}>Back</button>
</column>CopyComplete example in 3 files · Save each one at the path shown above it.
How it works
- App only creates the stack and shows it. Home is the first page.
- Home and Detail call navigation() to reach the same stack.
- Home stays alive under Detail, so its draft survives the trip.
What you should see
Type a draft, click Open detail, then Back: Home reappears with the same draft.
Built on the public API
janelkit-router uses only the public API of the core, like any package you could write. Pages and Sections are .qml elements whose root is a JkDeck and that declare a JkHost property; PageStack and SectionSet are hosts (janelkit.ext.Host) that mount the pages with Container.mount. A repository test checks that it never imports anything internal.
Learn moreBuild your own package ↗
Versions and changes
janelkit-router shares the series with the core: janelkit-router 0.2.x.x works with janelkit 0.2.x.x and Python 3.10 or later. The last two numbers are its own.
0.2.0.0 is its first version. Until 0.1, navigation was part of the core: change from janelkit import pages, navigation, sections to from janelkit_router import pages, navigation, sections, and import the elements you use (from janelkit_router import Pages, Sections). The type of sections() is now called SectionSet. janel migrate makes these changes for you.
Learn moreChanges and migration ↗
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.