Skip to content

Commit f23f920

Browse files
committed
fix
1 parent 31a9631 commit f23f920

File tree

7 files changed

+299
-16
lines changed

7 files changed

+299
-16
lines changed

.changeset/quiet-cows-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rescript-relay-router": patch
3+
---
4+
5+
Fix clean needed to remove path param type annotations in route patterns emitted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let renderer = Routes.Root.Todos.ByStatusDecodedExtra.Route.makeRenderer(
2+
~prepare=_props => {
3+
()
4+
},
5+
~render=_props => {
6+
React.null
7+
},
8+
)

examples/client-rendering/src/routes/__generated__/RouteDeclarations.res

Lines changed: 72 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-rendering/src/routes/__generated__/Route__Root__Todos__ByStatusDecodedExtra_route.res

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-rendering/src/routes/__generated__/Routes.res

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-rendering/src/routes/todoRoutes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
}
1919
]
2020
},
21+
{
22+
"path": "extra/:byStatusDecoded:TodoStatusPathParam.t",
23+
"name": "ByStatusDecodedExtra",
24+
},
2125
{
2226
"path": ":todoId?showMore=bool",
2327
"name": "Single",

packages/rescript-relay-router/cli/RescriptRelayRouterCli__Types.res

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ module RoutePath: {
8686
currentRoutePath: list<string>,
8787
}
8888

89+
let cleanPathParamTypeAnnotations = p =>
90+
if p->String.includesFrom(":", 1) {
91+
":" ++
92+
p
93+
->String.sliceToEnd(~start=1)
94+
->String.split(":")
95+
->Array.get(0)
96+
->Option.getOr("")
97+
} else {
98+
p
99+
}
100+
89101
let make = (path, ~currentRoutePath) => {
90102
let cleanPath = path->String.split("?")->Array.get(0)->Option.getOr("")
91103
{
@@ -96,23 +108,16 @@ module RoutePath: {
96108
->List.reverse
97109
->List.concat(currentRoutePath.currentRoutePath)
98110
->List.filter(urlPart => urlPart != "")
99-
->List.map(p => {
100-
// Handle path params with explicit type annotations
101-
if p->String.includesFrom(":", 1) {
102-
":" ++
103-
p
104-
->String.sliceToEnd(~start=1)
105-
->String.split(":")
106-
->Array.get(0)
107-
->Option.getOr("")
108-
} else {
109-
p
110-
}
111-
}),
111+
->List.map(p => cleanPathParamTypeAnnotations(p)),
112112
}
113113
}
114114

115-
let getPathSegment = t => t.pathSegment
115+
let getPathSegment = t =>
116+
t.pathSegment
117+
->String.split("/")
118+
->Array.map(p => cleanPathParamTypeAnnotations(p))
119+
->Array.join("/")
120+
116121
let getFullRoutePath = t => "/" ++ t.currentRoutePath->List.reverse->List.toArray->Array.join("/")
117122

118123
let toPattern = t =>

0 commit comments

Comments
 (0)