Switch, Match & Index in SolidJS
From the SolidJS cheat sheet ยท Control Flow ยท verified Jul 2026
Switch, Match & Index
Multi-condition rendering with Switch/Match and primitive-keyed iteration with Index.
tsx
// Quick Reference
import { Switch, Match, Index } from "solid-js";
<Switch fallback={<p>Not found</p>}>
<Match when={route() === "home"}><Home /></Match>
<Match when={route() === "about"}><About /></Match>
</Switch>๐ก Switch renders the first matching Match โ use fallback for the default case
โก Index is keyed by position โ use it for primitive arrays (strings, numbers)
๐ In Index, the item is a signal but the index is a plain number โ opposite of For
๐ข For vs Index: For recycles DOM nodes by reference, Index recycles by position
switchmatchindexcontrol-flow