ECOSYSTEM / ROUTER

Sections

Parallel destinations, such as a sidebar or tabs, each with its own page stack that is kept while another one is shown.

Ecosystem package janelkit-router Navigation between screens: page stacks that keep their state, parallel sections, results with await and transitions. pip install janelkit-router
ROUTER · PAGE 3 / 6~2 min read
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

Destinations that keep their place

An application with a sidebar or tabs has several sections, and each one needs its own stack. sections(name=Component, …) creates them; <Sections of={areas} /> shows the current one. areas.show("people") switches without discarding anything: each section keeps its pages and their state. Inside a section, navigation() returns that section’s stack.

src/App.janel
<script lang="python">
from janelkit_router import sections, Sections
from pages.Home import Home

areas = sections(projects=Home, people=Home)
</script>

<window title="Sections" width={480} height={300}>
  <column>
    <row gap={8} padding={8}>
      <button on:click={areas.show("projects")}>Projects</button>
      <button on:click={areas.show("people")}>People</button>
      <text>Now in {areas.current}</text>
    </row>
    <Sections of={areas} />
  </column>
</window>
Copy
src/pages/Home.janel
<script lang="python">
from janelkit_router import navigation
from pages.Detail import Detail
nav = navigation()
</script>

<column padding={24} gap={12}>
  <text>Home page</text>
  <button on:click={nav.push(Detail)}>Open detail</button>
</column>
Copy
src/pages/Detail.janel
<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>
Copy

Complete example in 3 files · Save each one at the path shown above it.

How it works

  1. sections(projects=Home, people=Home) creates two stacks, each starting with its own Home page.
  2. Home calls navigation(), so Open detail pushes onto the stack of the section it belongs to.
  3. areas.current is reactive, so the header follows the switch.

What you should see

Open detail in Projects, switch to People: People shows its own Home page. Switch back: Projects is still on the detail page.

When sections are created, and what they cost

A section is created the first time it is shown. Switching to another one keeps it whole, with all its pages and their state, so coming back costs the same as showing it. While it is not shown, what it shows waits, as in {#hidden}: a data change in another section does not recalculate it.

Each section is a stack: areas["people"] gives it by name and areas.stack gives the visible one. areas.current, the name of the visible section, is reactive, and areas.names lists the names.

Common mistakes

  • Switching sections never asks before_leave, because nothing is discarded.
  • The script of a hidden section keeps running. Pause its timers with when=is_visible().

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.