Put the root view and the destinations inside the stack. Give a link and its destination the same value. Set the title of each screen with the navigationTitle modifier.
NavigationStackExample.tsx
import{Host,List,NavigationDestination,NavigationLink,NavigationStack,Text,VStack,}from'@expo/ui/swift-ui';import{
navigationTitle,
padding,}from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionNavigationStackExample(){return(<Hoststyle={{ flex:1}}><NavigationStack><Listmodifiers={[navigationTitle('Settings')]}><NavigationLinkvalue="account"><Text>Account</Text></NavigationLink><NavigationLinkvalue="notifications"><Text>Notifications</Text></NavigationLink></List><NavigationDestinationvalue="account"><VStackmodifiers={[padding({ all:20}),navigationTitle('Account'),]}><Text>Signed in as bird@example.com</Text></VStack></NavigationDestination><NavigationDestinationvalue="notifications"><VStackmodifiers={[padding({ all:20}),navigationTitle('Notifications'),]}><Text>All notifications are on.</Text></VStack></NavigationDestination></NavigationStack></Host>);}
Inside a List, a link renders as a row with a chevron. A destination has to be a direct child of the stack, however deeply the link that pushes it is nested.
Keep the links inside the NavigationStack itself. Content presented from the stack, such as a BottomSheet or a Popover, needs its own NavigationStack and its own destinations.
Any view as a link
A link can wrap any view.
NavigationLinkCardExample.tsx
import{Host,HStack,Image,NavigationDestination,NavigationLink,NavigationStack,Spacer,Text,VStack,}from'@expo/ui/swift-ui';import{
font,
foregroundStyle,
navigationTitle,
padding,}from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionNavigationLinkCardExample(){return(<Hoststyle={{ flex:1}}><NavigationStack><VStackmodifiers={[padding({ all:20}),navigationTitle('Today'),]}><NavigationLinkvalue="report"><HStackspacing={12}><ImagesystemName="chart.bar.fill"size={28}/><VStackalignment="leading"spacing={2}><Textmodifiers={[font({ textStyle:'headline'})]}>
Weekly report
</Text><Textmodifiers={[font({ textStyle:'caption'}),foregroundStyle('secondaryLabel'),]}>
Ready to read
</Text></VStack><Spacer/></HStack></NavigationLink></VStack><NavigationDestinationvalue="report"><VStackmodifiers={[padding({ all:20}),navigationTitle('Weekly report'),]}><Text>Sessions are up by 12% on last week.</Text></VStack></NavigationDestination></NavigationStack></Host>);}
Read and set the path
The stack keeps its own path by default. Pass path and onPathChange to drive it from state. The path holds the value of each pushed view, in push order. Set it to an empty array to return to the root view.
NavigationStackPathExample.tsx
import{Button,Host,List,NavigationDestination,NavigationLink,NavigationStack,Text,VStack,}from'@expo/ui/swift-ui';import{
navigationTitle,
padding,}from'@expo/ui/swift-ui/modifiers';import{ useState }from'react';constARTICLES=['Nesting','Migration','Song'];exportdefaultfunctionNavigationStackPathExample(){const[path, setPath]=useState<string[]>([]);return(<Hoststyle={{ flex:1}}><NavigationStackpath={path}onPathChange={setPath}><Listmodifiers={[navigationTitle('Articles')]}>{ARTICLES.map(article =>(<NavigationLinkkey={article}value={article}><Text>{article}</Text></NavigationLink>))}</List>{ARTICLES.map(article =>(<NavigationDestinationkey={article}value={article}><VStackspacing={12}modifiers={[padding({ all:20}),navigationTitle(article),]}><Text>
The chapter about {article.toLowerCase()}.
</Text><Buttonlabel="Back to the articles"onPress={()=>setPath([])}/></VStack></NavigationDestination>))}</NavigationStack></Host>);}
Add buttons to the navigation bar
Wrap the content in a Toolbar and put the buttons in Toolbar.Content.