xref: /expo/docs/pages/router/reference/redirects.mdx (revision 6eefacaa)
1---
2title: Redirects
3description: Learn how redirect URLs in Expo Router.
4hideTOC: true
5---
6
7You can redirect a request to a different URL based on some in-app criteria. Expo Router supports a number of different redirection patterns.
8
9## Redirect
10
11You can immediately redirect from a particular screen by using the `Redirect` component:
12
13```jsx
14import { View, Text } from 'react-native';
15/* @info */
16import { Redirect } from 'expo-router';
17/* @end */
18
19export default function Page() {
20  /* @info Some logic to determine if the user is logged in. */
21  const { user } = useAuth();
22  /* @end */
23
24  if (!user) {
25    /* @info Redirect to the login screen if the user is not authenticated. */
26    return <Redirect href="/login" />;
27    /* @end */
28  }
29
30  return (
31    <View>
32      <Text>Welcome Back!</Text>
33    </View>
34  );
35}
36```
37
38You can also redirect imperatively with the `useRouter` hook:
39
40```jsx
41import { Text } from 'react-native';
42import { useRouter, useFocusEffect } from 'expo-router';
43
44function MyScreen() {
45  const router = useRouter();
46
47  useFocusEffect(() => {
48    // Call the replace method to redirect to a new route without adding to the history.
49    // We do this in a useFocusEffect to ensure the redirect happens every time the screen
50    // is focused.
51    router.replace('/profile/settings');
52  });
53
54  return <Text>My Screen</Text>;
55}
56```
57