# Navigation

> Go to any screen, go back or reset your app's navigation from the desktop app, with React Navigation or Expo Router. It is opt-in.

Navigation adds commands to the [Commands](/docs/desktop/commands/) panel that move your app around: open a screen that has no button leading to it yet, with the params you choose, go back, or reset the stack. It can also log every screen change in the Console.

[Setting up Navigation in the SDK](/docs/sdk/navigation/)

![The navigation.navigate command in the Commands panel, with a route picked and its params filled in](/_astro/navigation-navigate-light.hoJx99xN_cQBPl.webp)![The navigation.navigate command in the Commands panel, with a route picked and its params filled in](/_astro/navigation-navigate-dark.B47UlJtt_ju5jv.webp)

The navigation.navigate command in the Commands panel, with a route picked and its params filled in

## Using navigation in the desktop app

### Running a navigation command

The navigation commands are listed under **Xerlock commands** in the Commands panel. Select one, fill in its parameters and choose **Run**, as with [any command](/docs/desktop/commands/#running-a-command).

| Command                   | What it does                                                                           |
| ------------------------- | -------------------------------------------------------------------------------------- |
| `navigation.navigate`     | Goes to the screen chosen in **route**, with the JSON object in **params**             |
| `navigation.goBack`       | Goes back in the focused navigator                                                     |
| `navigation.pop`          | Pops **count** screens off the focused stack, 1 by default                             |
| `navigation.popToTop`     | Pops the focused stack back to its first screen                                        |
| `navigation.reset`        | Resets navigation so the chosen screen is the only one, with optional **params**       |
| `navigation.dispatch`     | Dispatches a navigation action, such as `{ "type": "POP", "payload": { "count": 1 } }` |
| `navigation.currentRoute` | Shows the focused route and the full navigation state                                  |

### Choosing a screen

With Expo Router, **route** in `navigation.navigate` lists every file route by its href, such as `/suspects/[suspectId]`. Groups like `(tabs)` are kept, `index` is dropped, and layouts aren’t listed.

Otherwise, and for `navigation.reset` in every app, **route** lists the route names of the navigators that are mounted right now, such as `suspects/[suspectId]`. Nested navigators’ routes are listed together, each name once, and Xerlock works out the nesting when the command runs. A name used by more than one navigator goes to the first match, searching from the root navigator down.

The list updates whenever your app navigates. Type in the picker to filter it once it has 9 or more routes.

### Filling in params

Picking a route fills **params** with a starting point:

* A dynamic segment becomes an empty value: `/suspects/[suspectId]` gives `{ "suspectId": "" }` and `/evidence/[...path]` gives `{ "path": [] }`.
* Params your app has already opened that screen with are added, keeping the first value seen.
* With Expo Router, keys the screen reads with `useLocalSearchParams` or `useGlobalSearchParams` are added as `""`. Xerlock finds them in the screen’s source, and in the local files it imports, through Metro.

Picking another route replaces **params** only while it is empty or still the suggested text, so your own edits stay. **params** must be a JSON object.

### Logging screen changes

Turn on **Navigation** in the Console’s level filters to log each screen change as **Navigated to …**, with its `route`, the `path` of navigator routes leading to it, and its `params`. The level is off by default and listed only while the app has `navigation` set.

## Limits and Troubleshooting

* Without Expo Router, only mounted navigators are listed. A screen in a navigator that hasn’t rendered yet, such as a lazy tab you haven’t opened, appears after your app first visits it. Running a command for a name that isn’t mounted fails with `Route "…" isn't mounted right now`.
* With Expo Router, the `navigation.reset` list also includes Expo Router’s own routes, such as `__root`, `+not-found` and `_sitemap`.
* Search params are found by reading source, so they are a best guess. A key read with a computed name, such as `params[name]`, isn’t found, and files in `node_modules` aren’t read. Keys added while the app runs appear after a reload, or once the app opens the screen with them.
* `navigation.goBack` fails with `Nothing to go back to` on the first screen.
* **`navigation.navigate` and `navigation.reset` are missing** while the container hasn’t mounted. The other commands fail with `Navigation isn't ready yet` until it has.
