Pico Library This library has about 1.8 KBytes

The LemonadeJS router plugin is part of the official libraries and is distributed under the MIT. This controls which component is rendered and append to the page based on the route. This library is part of the PICO Library, which is a very smart and optimized library that does not require any external dependencies.



npm install @lemonadejs/router


Attribute Description
Router component
animation?: BooleanEnable the page change animation.
Route element
path: StringRoute to execute this page. This should be a regular expression string.
controller: ComponentComponent name.
url?: StringURL to load a remote template.
preload?: BooleanURL to load a remote template.


Event Description
Router component
onchange?: functionExecute the page changes.
onchange(newPage: Object, oldPage: Object) => void;
Route element
onenter?: functionWhen enters in the page
onenter(page: Object) => void;

Router SPA example

On the following example the pages are created from a local template and the other from a remote template define by the url attribute.

Two-way data binding and router library

Source code

<script src=""></script>
<script src=""></script>
<script src=""></script>

<link rel="stylesheet" href="" />

<div id='root'></div>
function Messages () {
    // Create one self for each interaction in the array
    let self = this;

    // Template
    let template = `
        <div class="option">
            <div class="option-image">
                <div class="option-badge solid"></div>
                <img src="/templates/default/img/nouser.png" />
            <div class="option-header">
                <div class="option-name">{{}}</div>
                <div class="option-small">{{self.message}}</div>
            <div class="option-date prettydate">1 mon ago</div>

    return lemonade.element(template, self);

function Profile(html) {
    let self = this;
    return lemonade.element(html, self);

function Compose(html) {
    let self = this;
    return lemonade.element(html, self);

function Home() {
    let self = this; = [
            name: 'Alexander Foster',
            message: 'Lorem ipsum dolor sit amet, consectetur adipiscing'
            name: 'Alfie Chapman',
            message: 'Lorem ipsum dolor sit amet, consectetur adipiscing'
            name: 'Fabian Byrne',
            message: 'Lorem ipsum dolor sit amet, consectetur adipiscing'

    let template = `
                <Icon href="/tests/home" icon="menu" />
                <Header title="Inbox"/>
            <div class="block-title">Messages</div>
            <div class="options"><Messages @loop="" /></div>

    return lemonade.element(template, self, { Messages, Navbar });

function App() {
    let self = {};

    // In this example, Profile and Compose templates are loaded from a remote ajax call
    let template = `<>
        <Router animation="true">
            <Route path="/tests/home" controller="Home" />
            <Route path="/tests/profile" controller="Profile" url="/tests/profile/1" />
            <Route path="/tests/compose" controller="Compose" url="/tests/compose/1" />
            <Icon content="inbox" title="Inbox" route="/tests/home" />
            <Icon content="create" title="New message" route="/tests/compose" />
            <Icon content="person" title="Profile" route="/tests/profile" />

    return lemonade.element(template, self, { Router, Toolbar, Home, Profile, Compose });

lemonade.render(App, document.getElementById('root'));