Every directory in src/app normally adds a segment to the URL. That gets in the way when you want sign-in screens in one folder without every URL starting with /auth. Route groups give you the folder without the segment, and the same rule decides which file the user sees when the app opens, because Expo Router doesn't read the first screen from your code.

Key terms

  • Route group: a directory whose name is wrapped in parentheses, such as (auth), which groups routes without affecting their URL.
  • Initial route: the first screen the app shows, which Expo Router finds as the first index.tsx that matches the / URL instead of reading it from a setting.

Parentheses keep a folder out of the URL

The reading tracker, reorganized into two groups:

text
src/app/
  _layout.tsx
  (auth)/
    sign-in.tsx
    create-account.tsx
  (reader)/
    index.tsx
    stats.tsx
    shelf/
      wishlist.tsx

(auth)/sign-in.tsx answers /sign-in, and (reader)/stats.tsx answers /stats. A group doesn't factor into the URL, even though the file is not directly in src/app. A regular folder inside a group still counts, so (reader)/shelf/wishlist.tsx answers /shelf/wishlist. Moving a file between (auth) and (reader) changes the tree and leaves its URL as it was.

Expo Router recognizes a group by the parentheses around its name. When it builds the URL it shows for a route, and when it matches a URL coming in, it works from the path with the group segments removed.

A group has to be a directory. A route file whose own name is a group, such as (reader).tsx, makes Expo Router throw an Invalid route error that says routes "cannot end with '(group)' syntax".

Groups matter more once layout files, covered in the next section, start defining how routes relate to each other: a group gives a layout a folder to live in without touching any URL.

Picking the first screen at /

You don't write an initial route anywhere in your code. When the app opens, Expo Router looks for the first index.tsx file that matches the / URL. In the default template, that file is src/app/index.tsx.

Groups change where that file can live. Since a group adds nothing to the URL, (reader)/index.tsx matches / and becomes the default route for the whole app. That is how you start the app inside a set of screens: put them in a group, make the screen you want first that group's index.tsx, and / takes the user straight to it. The ReadingNowScreen example is that file. Nothing inside it mentions / or the group:

tsx
export default function ReadingNowScreen() {

Its place in the tree is the only thing that makes it the first screen.

Groups can also nest. To match /, Expo Router collapses every level of group segments before testing the routes, so an index file two groups deep, such as (reader)/(today)/index.tsx, still matches /.

Reading a tree for the first screen

To predict what opens at launch, strip every group name from each path and look for the index file that is left at the top:

  • _layout.tsx renders before anything else in the app, but it is not a page, so it never answers / by itself.
  • (auth)/sign-in.tsx and (reader)/stats.tsx keep their file names as the only segment, so they answer /sign-in and /stats.
  • (reader)/index.tsx loses its group and its index segment, leaving /. This is the screen the app opens on.

A file's name doesn't make it the first screen either. A home.tsx placed directly in src/app answers /home, not /. And if you renamed (reader) to reader, without parentheses, its index file would answer /reader, and nothing in this tree would answer / anymore.

Code Examples

tsx
import { Text, View } from 'react-native';

// src/app/(reader)/index.tsx: the (reader) group adds nothing to the URL,
// so this file answers / and is the screen the app opens on
export default function ReadingNowScreen() {
  return (
    <View>
      <Text>Currently reading</Text>
      <Text>Chapter 7 of 22</Text>
    </View>
  );
}
✓ Completed