Skip to content
Brandon Jordan edited this page Aug 30, 2022 · 15 revisions

jsUI comes with a built-in router to allow you to separate your views into javascript files like pages, with one javascript file dictating to the jsUI router where all of this content should go.

import * as jsUI from 'javascript-ui';
import home from './views/home.js';
import page1 from './views/page1.js';
import page2 from './views/page2.js';

jsUI.router([
    {url: '/', title: 'Home', name: 'home', view: home},
    {url: '/page1', title: 'Page 1',  name: 'page1', view: page1},
    {url: '/page2', title: 'Page 2', name: 'page2', view: page2}
]);

Route Parameters

url

Required

The url of the page. This should always be prefixed with a forward slash.

title

Optional (but recommended)

The title of the page.

name

Optional (but recommended)

Name of the route you can refer to this later using the routeTo() or route() functions.

view

Required

Takes an array of jsUI elements or single jsUI element.

Functions

Hyperlink().route(name: string)

The Hyperlink() element has a route() method that you supply a route name to assign the url of the route with that name.

route(name: string)

This function takes the name of a route and returns the url of the route with that name. Returns a '#' if the route does not exist.

routeTo(name: string)

This function tells the router to change the current route to the route with that name.

Clone this wiki locally