@becklyn/router

The JS implementation of Symfony's Router.

Usage no npm install needed!

<script type="module">
  import becklynRouter from 'https://cdn.skypack.dev/@becklyn/router';
</script>

README

Symfony JavaScript Router

This is a modern implementation of the JS router for generation Symfony routes. Best to be used with the JavaScript routing bundle.

Initialization

For example like this (using mojave):

import {initFromGlobalData} from "mojave/init"; 
import {Router} from "@becklyn/router";

let router = initFromGlobalData("RouterInit", new Router());

A manual way to wire it up to global data is like this:

function loadGlobalData (key, handler)
{
    if (undefined === window[key])
    {
        return;
    }

    // replace global callback
    window[key].init = (data) => handler.init(data);
    // handle current data
    handler.init(window[key].data);
}

let router = new Router();
loadGlobalData("RouterInit", router);