Pico Library This library has less than 2 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?: Boolean Enable the page change animation.
Route element
path: String Route to execute this page. This should be a regular expression string.
controller: Component Component name.
url?: String URL to load a remote template.
preload?: Boolean URL to load a remote template.


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

Router SPA example

The router loads the page content from a remote HTML file in the following example.

LemonadeJS router example
<link rel="stylesheet" href="|Roboto|Material+Icons" />
<link rel="stylesheet" href="" />
<link rel="stylesheet" href="" />
<link rel="stylesheet" href="" />
<link rel="stylesheet" href="" type="text/css" />

<script src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>

<div id='root'></div>
function List () {
    // Create one self for each interaction in the array
    const self = this;
    // Template
    return `<div class="form-group option" style="padding: 8px">
        <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>

function Home() {
    const self = this;

    self.onenter = function() {
    }; = [
        { name: 'Alexander Foster', message: 'Lorem Ipsum é...' },
        { name: 'Alfie Chapman', message: 'Lorem Ipsum é ...' },
        { name: 'Fabian Byrne', message: 'Lorem Ipsum é...' }

    return `<>
            <Icon href="/tests/home" icon="menu" />
            <Text title="Inbox"/>
            <Icon />
        <div class="block-title">Messages</div>
        <div class='section-container'>
            <div class="options"><List :loop="" /></div>

function App() {
    const self = this;

    self.test = function() {

    return `<>
        <Router animation="true" onchange="{{self.test}}">
            <Route path="/tests/home" controller="Home" />
            <Route path="/tests/compose" url="/tests/compose/1" />
            <Route path="/tests/profile" url="/tests/profile/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" />

// Set the components
lemonade.setComponents({ Router, Toolbar, Home, Navbar, List });
// Render
lemonade.render(App, document.getElementById('root'));