Skip to content

πŸ“¦ JSON-Based Routing in WBC-Routes2 ​

JSON is a universal format for defining structured data β€” and WBC-Routes2 makes it routeable!

By passing a JSON object to a route's item prop, you can dynamically render Vue components, markdown, layout structures, and even interactive behavior, all from data.


πŸ”Ή Basic JSON Object Rendering ​

You can route to a static JSON object like this:

js
{
  path: "/json/basic",
  name: "JsonBasic",
  component: WBC,
  props: {
    item: {
      comp: "JsonViewer",
      options: {
        value: { name: "Wissem", age: 30, active: true }
      }
    }
  }
}

βœ… The JsonViewer global component will render your object with toggles, colorized keys, and nested display.


πŸ”Έ Render Lists from JSON ​

Pass JSON as arrays or objects into a list-like display using Markdown or HTML renderers.

js
{
  path: "/json/list",
  name: "JsonList",
  component: WBC,
  props: {
    item: {
      comp: "MD",
      options: {
        html: "<~ol>",
        src: "- Item 1\n- Item 2\n- Item 3"
      }
    }
  }
}

🧩 Combine this with interactive buttons or file content to build dashboards on-the-fly.


πŸ”Έ JSON with Events ​

Inject interactivity through event bindings in the options.on object.

js
{
  path: "/json/event",
  name: "JsonEvent",
  component: WBC,
  props: {
    item: {
      comp: "VBtn",
      dive: true,
      options: {
        class: "success",
        html: "Click me",
        on: {
          click: that => () => {
            alert("Hello from JSON-driven route!");
          }
        }
      }
    }
  }
}

πŸ’‘ You’re not limited to read-only data. Full event lifecycles are supported.


πŸ” Dynamic JSON Mapped to Layouts ​

Here's a full Vue layout mapped from structured JSON:

js
{
  path: "/json/layout",
  name: "JsonLayout",
  component: WBC,
  props: {
    item: [
      "<~VContainer|pa-5 grey lighten-4>",
      "<VRow|justify-center>",
      {
        comp: "VCol",
        options: {
          cols: 6,
          html: {
            comp: "VAlert",
            options: {
              type: "info",
              text: true,
              html: "Rendered from JSON layout"
            }
          }
        }
      }
    ]
  }
}

πŸ“ You can control columns, rows, colors, spacing, and more β€” all from JSON.


πŸ§ͺ Reactive JSON with dive ​

To make the JSON reactive (data-bound), use:

js
{
  dive: true,
  comp: "div",
  options: {
    html: "Your score is: ``{this.score}",
    on: {
      mounted: that => {
        that.score = 42;
      }
    }
  }
}

πŸ” Now any property you assign inside that becomes available to interpolate in your text and children components.


βœ… Summary ​

FeatureSupported
JSON to Vue Layoutsβœ…
Dynamic Event Bindingβœ…
Reactive Propertiesβœ…
File + JSON Mixβœ…
Multi-language JSONβœ