Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Aug 19, 2024
1 parent 31a9631 commit f23f920
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-cows-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rescript-relay-router": patch
---

Fix clean needed to remove path param type annotations in route patterns emitted.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let renderer = Routes.Root.Todos.ByStatusDecodedExtra.Route.makeRenderer(
~prepare=_props => {
()
},
~render=_props => {
React.null
},
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/client-rendering/src/routes/__generated__/Routes.res

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/client-rendering/src/routes/todoRoutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
}
]
},
{
"path": "extra/:byStatusDecoded:TodoStatusPathParam.t",
"name": "ByStatusDecodedExtra",
},
{
"path": ":todoId?showMore=bool",
"name": "Single",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ module RoutePath: {
currentRoutePath: list<string>,
}

let cleanPathParamTypeAnnotations = p =>
if p->String.includesFrom(":", 1) {
":" ++
p
->String.sliceToEnd(~start=1)
->String.split(":")
->Array.get(0)
->Option.getOr("")
} else {
p
}

let make = (path, ~currentRoutePath) => {
let cleanPath = path->String.split("?")->Array.get(0)->Option.getOr("")
{
Expand All @@ -96,23 +108,16 @@ module RoutePath: {
->List.reverse
->List.concat(currentRoutePath.currentRoutePath)
->List.filter(urlPart => urlPart != "")
->List.map(p => {
// Handle path params with explicit type annotations
if p->String.includesFrom(":", 1) {
":" ++
p
->String.sliceToEnd(~start=1)
->String.split(":")
->Array.get(0)
->Option.getOr("")
} else {
p
}
}),
->List.map(p => cleanPathParamTypeAnnotations(p)),
}
}

let getPathSegment = t => t.pathSegment
let getPathSegment = t =>
t.pathSegment
->String.split("/")
->Array.map(p => cleanPathParamTypeAnnotations(p))
->Array.join("/")

let getFullRoutePath = t => "/" ++ t.currentRoutePath->List.reverse->List.toArray->Array.join("/")

let toPattern = t =>
Expand Down

0 comments on commit f23f920

Please sign in to comment.