Skip to content

Commit

Permalink
docs(start): correctly import the redirect fn
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Sep 15, 2024
1 parent 71edc6a commit cab3b51
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/framework/react/start/server-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ Server functions can throw a `redirect` error to redirect the user to a differen
- During SSR, redirects are handled by sending a 302 response to the client with the new location
- On the client, redirects are handled by the router automatically from within a route lifecycle or a component that uses the `useServerFn` hook. If you call a server function from anywhere else, redirects will not be handled automatically.

To throw a redirect, you can use the `redirect` function exported from the `@tanstack/start` package:
To throw a redirect, you can use the `redirect` function exported from the `@tanstack/react-router` package:

```tsx
import { createServerFn, redirect } from '@tanstack/start'
import { redirect } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/start'

export const doStuff = createServerFn('GET', async () => {
// Redirect the user to the home page
Expand All @@ -365,7 +366,8 @@ Redirects can utilize all of the same options as `router.navigate`, `useNavigate
Redirects can also set the status code of the response by passing a `status` option:

```tsx
import { createServerFn, redirect } from '@tanstack/start'
import { redirect } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/start'

export const doStuff = createServerFn('GET', async () => {
// Redirect the user to the home page with a 301 status code
Expand All @@ -383,7 +385,8 @@ export const doStuff = createServerFn('GET', async () => {
You can also set custom headers on a redirect by passing a `headers` option:

```tsx
import { createServerFn, redirect } from '@tanstack/start'
import { redirect } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/start'

export const doStuff = createServerFn('GET', async () => {
// Redirect the user to the home page with a custom header
Expand Down

0 comments on commit cab3b51

Please sign in to comment.