Skip to content

Commit 119e1ba

Browse files
authored
Merge pull request #6 from inertiajs/handle-redirects-on-inertia-routes
Handle redirects on inertia views
2 parents 97f4fc7 + 2c7e739 commit 119e1ba

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

inertia/http.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def decorator(func):
8181
@wraps(func)
8282
def inner(request, *args, **kwargs):
8383
props = func(request, *args, **kwargs)
84+
85+
# if something other than a dict is returned, the user probably wants to return a specific response
86+
if not isinstance(props, dict):
87+
return props
88+
8489
return render(request, component, props)
8590

8691
return inner

inertia/tests/test_rendering.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def test_proper_status_code(self):
6666
200
6767
)
6868

69+
def test_redirects_from_inertia_views(self):
70+
self.assertEqual(
71+
self.inertia.get('/inertia-redirect/').status_code,
72+
302
73+
)
74+
6975
class LazyPropsTestCase(InertiaTestCase):
7076
def test_lazy_props_are_not_included(self):
7177
self.assertJSONResponse(

inertia/tests/testapp/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
path('lazy/', views.lazy_test),
1111
path('complex-props/', views.complex_props_test),
1212
path('share/', views.share_test),
13+
path('inertia-redirect/', views.inertia_redirect_test),
1314
]

inertia/tests/testapp/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def empty_test(request):
2323
def redirect_test(request):
2424
return redirect(empty_test)
2525

26+
@inertia('TestComponent')
27+
def inertia_redirect_test(request):
28+
return redirect(empty_test)
29+
2630
@inertia('TestComponent')
2731
def props_test(request):
2832
return {

0 commit comments

Comments
 (0)