Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch all routes #29

Open
amiralies opened this issue Jan 5, 2021 · 1 comment
Open

Catch all routes #29

amiralies opened this issue Jan 5, 2021 · 1 comment

Comments

@amiralies
Copy link

How should one use catch all routes in router?
https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes

I think there's no way of doing this zero cost, right?
we should use an abstract type and then convert that type to an internal type like:

type query = String(string) | Array(array<string>)
type router = {
  // ...
  query: Js.Dict.t<query>,
}
@ryyppy
Copy link
Owner

ryyppy commented Jan 22, 2021

Jup, that's a union type..

probably something like this:

module Query: {
  type t
  type case = Array(array<string>) | String(string)
  let classify: t => case
}
= {
  type t
  type case = Array(array<string>) | String(string)

  external unsafeToArray: t => array<string> = "%identity"
  external unsafeToString: t => string = "%identity"

  let classify = (value: t) => {
    if %raw(`function (a) { return  a instanceof Array}`)(value) {
      Array(unsafeToArray(value))
    } else {
      String(unsafeToString(value))
    }
  }
}

Playground Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants