Router
A tradução desta página não existe ou está desatualizada, por isso é mostrada em inglês. Ler em inglês
Own the app navigation tree. With component routes you write it in app.tsx; with file routes the compiler generates it from app/.
Declare a home and detail stack
import { Link, Route, Router, Text, VStack, routes, type RouteTo, type ScreenProps } from 'kuito';
declare module 'kuito' {
interface Routes {
index: RouteTo;
show: RouteTo<{ id: number }>;
settings: RouteTo;
}
}
function Home() {
return (
<VStack padding={16}>
<Link to={routes.show({ id: 42 })}>
<Text>Show 42</Text>
</Link>
</VStack>
);
}
function Show({ id }: ScreenProps<{ id: number }>) {
return <Text padding={16}>{`Show ${id}`}</Text>;
}
function Settings() {
return <Text padding={16}>Settings</Text>;
}
export default function App() {
return (
<Router>
<Route name="index" path="/" screen={Home} title="Home" />
<Route
name="show"
path="/show/:id"
params={{ id: Number }}
screen={Show}
title={({ id }) => `Show ${id}`}
/>
<Route name="settings" path="/settings" screen={Settings} presentation="sheet" />
</Router>
);
}Behavior
Use one Router per app. Route parameters are typed; route names identify destinations. An app with file routes writes no Router: its route files and layout are the tree. kuito create --routes components starts an app whose app.tsx is one, with the routes typed by a declare module 'kuito' block.
Continue
Read Navigation for a complete workflow. See the complete prop reference for types and documented defaults.
Referência
Assinaturas
Props: RouterProps
Props (incluindo props herdadas) 3
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
initial | Destination<unknown> | Não | The first screen shown; the first route's by default. |
linking | boolean | Não | Deep links: the link that launched the app, and each one that arrives while it runs, navigate to the route their path matches. Off by default. |
children | KuitoNode | Sim | — |
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.