---
title: "Split View Navigator"
description: "Keep a sidebar selection beside its detail pages with the split view navigator."
---

# Split View Navigator

`createSplitViewNavigator` keeps its first screen in the sidebar and places the other screens in a content stack. Use it when the sidebar selects data, such as a folder whose messages appear beside it:

```tsx [src/mail.tsx]
import * as Gtk from "@gtkx/gi/gtk";
import {
    AdwSidebar,
    AdwSidebarItem,
    AdwSidebarSection,
    AdwStatusPage,
} from "@gtkx/jsx/adw";
import { GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
import {
    createSplitViewNavigator,
    type SplitViewScreenProps,
} from "@gtkx/navigation";

type MailParams = {
    Folders: undefined;
    Messages: { folder: string };
    Message: { id: string };
};

const Split = createSplitViewNavigator<MailParams>();

const Folders = ({
    navigation,
}: SplitViewScreenProps<MailParams, "Folders">) => (
    <AdwSidebar
        onActivated={() => navigation.navigate("Messages", { folder: "Inbox" })}
    >
        <AdwSidebarSection>
            <AdwSidebarItem title="Inbox" />
        </AdwSidebarSection>
    </AdwSidebar>
);

const Messages = ({
    navigation,
}: SplitViewScreenProps<MailParams, "Messages">) => (
    <GtkButton
        label="Open message 1"
        halign={Gtk.Align.CENTER}
        valign={Gtk.Align.CENTER}
        onClicked={() => navigation.navigate("Message", { id: "1" })}
    />
);

const Message = ({ route }: SplitViewScreenProps<MailParams, "Message">) => (
    <GtkLabel label={`Message ${route.params.id}`} />
);

export const Mail = () => (
    <Split.Navigator
        initialRouteName="Messages"
        collapseCondition="max-width: 500sp"
        minSidebarWidth={220}
        maxSidebarWidth={300}
        sidebarWidthFraction={0.25}
        contentPlaceholder={
            <AdwStatusPage
                iconName="mail-unread-symbolic"
                title="No Folder Selected"
                description="Pick a folder to read what is in it."
            />
        }
    >
        <Split.Screen
            name="Folders"
            component={Folders}
            options={{ title: "Mail" }}
        />
        <Split.Screen
            name="Messages"
            component={Messages}
            initialParams={{ folder: "Inbox" }}
            options={({ route }) => ({ title: route.params.folder })}
        />
        <Split.Screen
            name="Message"
            component={Message}
            options={{ headerEnd: <GtkButton label="Reply" /> }}
        />
    </Split.Navigator>
);
```

<figure class="result">
    <img class="result-light" src="/figures/guide-navigation-split-view-light.png" width="720" height="420" loading="lazy" alt="A window with a sidebar titled Mail holding a selected Inbox row, beside a content pane whose header bar is titled Inbox above a centered Open message 1 button." />
    <img class="result-dark" src="/figures/guide-navigation-split-view-dark.png" width="720" height="420" loading="lazy" alt="A window with a sidebar titled Mail holding a selected Inbox row, beside a content pane whose header bar is titled Inbox above a centered Open message 1 button." />
    <figcaption>Captured from the sample above. The navigator opens on the Inbox folder, which the sidebar selects first.</figcaption>
</figure>

`AdwSidebar` selects its first item on its own, and `activated` fires only when the user activates a row. The sample therefore names a content screen in `initialRouteName`, with `initialParams`, so the pane opens on the folder the sidebar shows as selected instead of on the placeholder.

The navigator comes from `@gtkx/navigation` and renders inside a [`NavigationContainer`](/guide/navigation#navigationcontainer).

## Selecting content

In a split view, `navigate` selects a content route: it updates that route and removes pages above it. Use `push` to keep multiple copies of a content page.

A content route that is not open yet is pushed above the current one, as in a stack. In a sidebar of distinct section screens, as in a settings app, `navigate("Proxy")` from Wi-Fi therefore leaves a Back button to Wi-Fi, and `popTo` replaces only the top page, which keeps the previous section beneath a section's sub-page. Reset the content instead, keeping the sidebar's own route so the sidebar is not remounted:

```tsx
import { GtkLabel, GtkListBox, GtkListBoxRow } from "@gtkx/jsx/gtk";
import type { SplitViewScreenProps } from "@gtkx/navigation";

type SettingsParams = {
    Sections: undefined;
    Wifi: undefined;
    Proxy: undefined;
};

const sections = [
    { name: "Wifi", label: "Wi-Fi" },
    { name: "Proxy", label: "Proxy" },
] as const;

const Sections = ({
    navigation,
    route,
}: SplitViewScreenProps<SettingsParams, "Sections">) => (
    <GtkListBox
        cssClasses={["navigation-sidebar"]}
        onRowActivated={(row) => {
            const section = sections[row.getIndex()];
            if (section)
                navigation.reset({
                    index: 1,
                    routes: [route, { name: section.name }],
                });
        }}
    >
        {sections.map((section) => (
            <GtkListBoxRow key={section.name}>
                <GtkLabel label={section.label} xalign={0} />
            </GtkListBoxRow>
        ))}
    </GtkListBox>
);
```

The sidebar stays pinned beneath the content routes. Going back from the first content page clears the selection and restores `contentPlaceholder`, which sits below an untitled header bar so the window keeps its controls.

Content pages use the [stack's](/guide/navigation#stack-navigator) headers, back controls and transition events. The first selection fills an empty pane and emits no page transition.

Focus follows the selected content route even when the sidebar remains visible. A sidebar's `useFocusEffect` therefore stops when a content page is selected; refresh sidebar data based on the data source or navigation state instead.

## Collapsing the panes

`collapseCondition` collapses the panes while an [`Adw.BreakpointCondition`](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/type_func.BreakpointCondition.parse.html) holds, measured against the navigator's size. Setting `collapsed` from a breakpoint's `onApply` and `onUnapply` handlers lands after GTK has moved focus, and widening the window can then select the focused sidebar row. Use `collapsed` when the layout depends on application state rather than size.

As with window breakpoints, give the window a minimum size the collapsed layout fits:

```tsx
import { AdwApplicationWindow } from "@gtkx/jsx/adw";
import { NavigationContainer } from "@gtkx/navigation";

export const App = () => (
    <AdwApplicationWindow title="Mail" widthRequest={360} heightRequest={294}>
        <NavigationContainer>
            <Mail />
        </NavigationContainer>
    </AdwApplicationWindow>
);
```

`useSplitViewCollapsed()` tells the navigator's screens whether the panes are collapsed, whether `collapsed` or `collapseCondition` collapsed them. libadwaita's [`AdwSidebar`](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/class.Sidebar.html) switches to page mode with the breakpoint that collapses its split view, so a sidebar screen reads the hook instead of repeating the condition in a window breakpoint:

```tsx
import * as Adw from "@gtkx/gi/adw";
import { AdwSidebar, AdwSidebarItem, AdwSidebarSection } from "@gtkx/jsx/adw";
import {
    type SplitViewScreenProps,
    useSplitViewCollapsed,
} from "@gtkx/navigation";

const folders = ["Inbox", "Sent", "Archive"];

const Folders = ({
    navigation,
}: SplitViewScreenProps<MailParams, "Folders">) => {
    const isCollapsed = useSplitViewCollapsed();

    return (
        <AdwSidebar
            mode={isCollapsed ? Adw.SidebarMode.PAGE : Adw.SidebarMode.SIDEBAR}
            onActivated={(index) => {
                const folder = folders[index];
                if (folder) navigation.navigate("Messages", { folder });
            }}
        >
            <AdwSidebarSection>
                {folders.map((folder) => (
                    <AdwSidebarItem key={folder} title={folder} />
                ))}
            </AdwSidebarSection>
        </AdwSidebar>
    );
};
```

The value changes after libadwaita has laid out the collapsed or widened panes, so use it for how a screen presents itself rather than to collapse anything.

Sizing and sidebar placement are covered by the [split view configuration reference](/reference/@gtkx/navigation/type-aliases/SplitViewNavigationConfig).
