Defining dynamic paths

There are cases where there may be need for multiple similar screens where only thing that changes is some index value and the rest of the screen is the same. We can use dynamic path for this.

Usage

In flow part of manifest, inside screen object, we can define path value that feels similar to router path by seperating route sections with / and naming dynamic variables starting with $.

Example:

{
  "flow": [
    {
      "path": "agent/$index",
      "components": [...]
    }
  ]
}

In this case we will be able to navigate user to agent/1, agent/2, ... agent/other_value and user will land on this screen we defined with agent/$index.

This will also expose this route variable to jsonlogic and contents as route.params.index (index being the name of the path variable $index).

Example:

{
  "flow": [
    {
      "path": "agent/$index",
      "components": [...]
      "next": {
        "type": "jsonlogic",
        "schema": {
          "if": [
            {
              "<": [{"var": "route.params.index"}, 1]
            },
            {
              "cat": ["agent/", {"+": [{"var": "route.params.index"}, 1]}]
            },
            "summary"
          ]
        }
      }
    }
  ]
}

And in contents we can access this value like so:

"flow.agent.title","Fill out details for agent nr.{route.params.index}"

In this case we would also want to adjust field names for input components on this screen (also dynamically). For this we can use dynamic config.

Full example:

{
  "flow": [
  {
    "path": "agent/$index",
    "components": [
      {
        "type": "form",
        "config": {
          "components": [
            {
              "type": "form-input",
              "config": {
                "field_name": {
                  "type": "jsonlogic",
                  "schema": {
                    "cat": ["data.agents.", {"var": "route.params.index"}, ".name"]
                  }
                },
                "content_key": {
                  "label": "form.agent.label",
                  "placeholder": "form.agent.placeholder"
                }
              }
            }
          ],
          "footer_components": [
            {
              "type": "form-button-next",
              "config": {
                "content_key": "flow.next"
              }
            }
          ]
        }
      }
    ],
    "next": {
      "type": "jsonlogic",
      "schema": {
        "if": [
          {
            "<": [{"var": "route.params.index"}, 1]
          },
          {
            "cat": ["agent/", {"+": [{"var": "route.params.index"}, 1]}]
          },
          "summary"
        ]
      }
    }
  }
  ]
}

Last updated