Skip to content

Commit a37c360

Browse files
Add better path handling for controller index action
1 parent 7880b73 commit a37c360

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Saturn/Controller.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ module Controller =
4444
let lst =
4545
choose [
4646
yield GET >=> choose [
47-
if state.Index.IsSome then yield route "/" >=> (fun _ ctx -> state.Index.Value(ctx))
4847
if state.Add.IsSome then yield route "/add" >=> (fun _ ctx -> state.Add.Value(ctx))
4948
if state.Edit.IsSome then
5049
match typ with
@@ -64,6 +63,9 @@ module Controller =
6463
| Int64 -> yield routef "/%d" (fun input _ ctx -> state.Show.Value(ctx, unbox<'Key> input) )
6564
| Float -> yield routef "/%f" (fun input _ ctx -> state.Show.Value(ctx, unbox<'Key> input) )
6665
| Guid -> yield routef "/%O" (fun input _ ctx -> state.Show.Value(ctx, unbox<'Key> input) )
66+
if state.Index.IsSome then
67+
yield route "" >=> (fun _ ctx -> ctx.Request.Path <- PathString(ctx.Request.Path.ToString() + "/"); state.Index.Value(ctx))
68+
yield route "/" >=> (fun _ ctx -> state.Index.Value(ctx))
6769
]
6870
yield POST >=> choose [
6971
if state.Create.IsSome then yield route "/" >=> (fun _ ctx -> state.Create.Value(ctx))

0 commit comments

Comments
 (0)