Skip to content

Commit 7ebb2dd

Browse files
committed
added redirect documentation
1 parent 8a949ff commit 7ebb2dd

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

v1/the-basics/redirects.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public class UsersController : Controller
6363
});
6464
_context.SaveChanges();
6565

66-
return RedirectToAction("Index");
66+
return Inertia.Back();
67+
//
68+
// return RedirectToAction(nameof(Index));
6769
}
6870
}
6971
```
@@ -76,6 +78,12 @@ When redirecting after a `PUT`, `PATCH`, or `DELETE` request, you must use a `30
7678

7779
If you're using one of our official server-side adapters, all redirects will automatically be converted to `303` redirects.
7880

81+
When using `InertiaCore`, redirects created via `Inertia.Back()` are automatically converted to `303` responses. You may optionally pass a fallback URL (used when the `Referer` header is unavailable) and a custom status code:
82+
83+
```csharp
84+
return Inertia.Back(fallbackUrl, statusCode);
85+
```
86+
7987
## External Redirects
8088

8189
Sometimes it's necessary to redirect to an external website, or even another non-Inertia endpoint in your app while handling an Inertia request. This can be accomplished using a server-side initiated `window.location` visit via the `Inertia::location()` method.

v2/the-basics/redirects.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public class UsersController : Controller
6666
_context.Users.Add(new User { Name = request.Name, Email = request.Email });
6767
await _context.SaveChangesAsync();
6868

69-
return RedirectToAction("Index");
69+
return Inertia.Back();
70+
//
71+
// return RedirectToAction(nameof(Index));
7072
}
7173
}
7274
```
@@ -79,6 +81,12 @@ When redirecting after a `PUT`, `PATCH`, or `DELETE` request, you must use a `30
7981

8082
If you're using one of our official server-side adapters, all redirects will automatically be converted to `303` redirects.
8183

84+
When using `InertiaCore`, redirects created via `Inertia.Back()` are automatically converted to `303` responses. You may optionally pass a fallback URL (used when the `Referer` header is unavailable) and a custom status code:
85+
86+
```csharp
87+
return Inertia.Back(fallbackUrl, statusCode);
88+
```
89+
8290
## External Redirects
8391

8492
Sometimes it's necessary to redirect to an external website, or even another non-Inertia endpoint in your app while handling an Inertia request. This can be accomplished using a server-side initiated `window.location` visit via the `Inertia::location()` method.

v3/the-basics/redirects.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public class UsersController : Controller
6262
_context.Users.Add(new User { Name = request.Name, Email = request.Email });
6363
await _context.SaveChangesAsync();
6464

65-
return RedirectToAction("Index");
65+
return Inertia.Back();
66+
//
67+
// return RedirectToAction(nameof(Index));
6668
}
6769
}
6870
```
@@ -75,6 +77,12 @@ When redirecting after a `PUT`, `PATCH`, or `DELETE` request, you must use a `30
7577

7678
If you're using one of our official server-side adapters, all redirects will automatically be converted to `303` redirects.
7779

80+
When using `InertiaCore`, redirects created via `Inertia.Back()` are automatically converted to `303` responses. You may optionally pass a fallback URL (used when the `Referer` header is unavailable) and a custom status code:
81+
82+
```csharp
83+
return Inertia.Back(fallbackUrl, statusCode);
84+
```
85+
7886
## Preserving Fragments
7987

8088
Sometimes a user may visit a URL with a fragment, such as `/article/old-slug#section`, and the server needs to redirect to a different URL. The fragment from the original request is normally lost during the redirect.

0 commit comments

Comments
 (0)