For my project I created a linking API but I'm far from zero cost binding, since ReScript 10 and optional record attribute, it's seems less shitty and I think it's cool to discuss to have experts opinions about it.
type routeName = string
type rec pathConfig = {
path?: string,
exact?: bool,
initialRouteName?: routeName,
screens?: screens,
}
and screens = Js.Dict.t<pathConfig>
type config = {
initialRouteName?: routeName,
screens: screens,
}
type t = {
enabled?: bool,
prefixes: array<string>,
config?: config,
}
type routeNameAndConfig = (routeName, pathConfig)
let makeScreens = (screens: array<routeNameAndConfig>): screens => screens->Js.Dict.fromArray
let options = {
prefixes: [WebConst.origin],
config: {
initialRouteName: "app",
screens: [
(
"app",
{
screens: [
("news", {screens: [("newsList", {path: ""})]->makeScreens}),
(
"planning",
{
screens: [
(
"planningNav",
{
screens: [
("planningNewList", {path: "planning/news"}),
("planningList", {path: "planning"}),
]->makeScreens,
},
),
]->makeScreens,
},
),
(
"catalogue",
{
screens: [
(
"catalogueNav",
{
screens: [
("seriesList", {path: "series"}),
("authorsList", {path: "authors"}),
("publishersList", {path: "publishers"}),
]->makeScreens,
},
),
]->makeScreens,
},
),
]->makeScreens,
},
),
(
"modalNav",
{
screens: [
("volumeDetail", {path: "volumes/:id"}),
("editionDetail", {path: "editions/:id"}),
("serieDetail", {path: "series/:id"}),
("publisherDetail", {path: "publishers/:id"}),
("authorDetail", {path: "authors/:id"}),
]->makeScreens,
},
),
(
"collectionPublic",
{
initialRouteName: "collectionPublicNav",
path: "user/:username",
screens: [
(
"collectionPublicNav",
{
screens: [
("collectionPublicList", {path: "collection"}),
("planningPersoPublicList", {path: "planning"}),
("missingPublicList", {path: "missing"}),
("wishPublicList", {path: "wish"}),
]->makeScreens,
},
),
("collectionPublicEdition", {path: "edition/:editionId"}),
]->makeScreens,
},
),
]->makeScreens,
},
}