Skip to content
MohammadAli Arjomand edited this page Aug 26, 2023 · 2 revisions

You can create a page via singlighter

node singlighter make:page HomePage

Pages will creating in ~/Scripts/Pages

Template Method

template is a required method in every pages. In template you must return HTML codes as string

class HomePage extends Page {
    template() {
        return "<h1>Hello, SinglightJs!</h1>";
    }
}

Setup Method

setup is a optional method in pages. setup will running before loading page (no reloading)

class HomePage extends Page {
    template() {
        return "<h1>Hello, SinglightJs!</h1>";
    }
    setup() {
        console.log("Hi there!");
    }
}

Route Parameters

With this.route you can use route parameters

For example, in this route

router.addRoute("/posts/{id}", PostShowPage);

You can access to id value by this.route.id

class PostShowPage extends Page {
    template() {
        return "<h1>Post Show</h1>";
    }
    setup() {
        console.log(this.route.id);
    }
}
Clone this wiki locally