Manual installation
Edit page
Learn how to add Expo Router to an existing project with these detailed instructions.
Follow the steps below if you have an existing project and want to add Expo Router. For new projects, see the Quick start in the introduction guide.
Prerequisites
Make sure your computer is set up for running an Expo app.
1
Install dependencies
You'll need to install the following dependencies:
- npx expo install expo-router react-native-safe-area-context react-native-screens expo-linking expo-constants expo-status-barThe above command will install versions of these libraries that are compatible with the Expo SDK version your project is using.
2
Setup entry point
For the property main, use the expo-router/entry as its value in the package.json. The initial client file is src/app/_layout.tsx (or app/_layout.tsx if not using the src directory).
{ "main": "expo-router/entry" }
Custom entry point to initialize and load side-effects
You can create a custom entry point in your Expo Router project to initialize and load side-effects before your app loads the root layout (src/app/_layout.tsx). Below are some of the common cases for a custom entry point:
- Initializing global services like analytics, error reporting, and so on.
- Setting up polyfills
- Ignoring specific logs using
LogBoxfromreact-native
-
Create a new file in the root of your project, such as index.js. After creating this file, the project structure should look like this:
srcapp_layout.tsxindex.jspackage.jsonOther project files -
Import or add your custom configuration to the file. Then, import
expo-router/entryto register the app entry. Remember to always import it last to ensure all configurations are properly set up before the app renders.index.js// Import side effects first and services // Initialize services // Register app entry through Expo Router import 'expo-router/entry'; -
Update the
mainproperty in package.json to point to the new entry file.package.json{ "main": "index.js" }
3
Modify project configuration
Add a deep linking scheme and enable typed routes in your app config:
{ "scheme": "your-app-scheme", "experiments": { "typedRoutes": true } }
If you are developing your app for web, install the following dependencies:
- npx expo install react-native-web react-domThen, enable Metro web support by adding the following to your app config:
{ "web": { "bundler": "metro" } }
4
Modify babel.config.js
If your project has a babel.config.js file, ensure you use babel-preset-expo as the preset. If you don't need any custom Babel configuration, you can delete the file entirely:
module.exports = function (api) { api.cache(true); return { presets: ['babel-preset-expo'], }; };
5
Configure path aliases
If you are using the src directory, add path aliases to your tsconfig.json so you can use short import paths like @/components/button instead of relative paths:
{ "extends": "expo/tsconfig.base", "compilerOptions": { "strict": true, "paths": { "@/*": ["./src/*"] } }, "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"] }
The @/* alias maps to the src directory in the above example.
6