When you want to move between a page, you have a few options. Examples on this page will reference this routing structure:
_layout.tsx
Wraps all files in this directory and below
index.tsx
Matches "/"
blog.tsx
index.tsx
Matches "/blog"
[slug].tsx
Matches a single sub-path of "/blog", like "/blog/hello"
Link
You can use the Link component as follows:
app/index.tsx
import{ Link }from'one'
exportdefaultfunctionHomePage(){
return(
<>
<Linkhref="/blog">
Go to the blog
</Link>
<Linkhref="/blog/introducing-one">
Go to the Introducing One article
</Link>
</>
)
}
Link accepts the following props, where Href is your typed file system routes (or a string if you turn off typed file system routing) and TextProps is the React Native Text element props:
exportinterfaceLinkPropsextendsTextProps{
/** Path to route to. */
href: Href
/** Forward props to child component. Useful for custom buttons. */
asChild?:boolean
/** Should replace the current route without adding to the history. */
replace?:boolean
/** Should push the current route */
push?:boolean
/** On web, this sets the HTML `class` directly. On native, can be used with CSS interop tools. */
* **Web only:** Specifies that the `href` should be downloaded when the user clicks on the link.
*/
download?:string
}
useLinkTo
This hook will generate both an href string and an onPress function, see the useLinkTo docs for how to use it.
useRouter
This hook returns a static object used for routing. It will never update, and is only used for imperatively controlling the router. Useful for programmatically controlling the routing, and choosing between a push or replace.