A basic router implementation to FerrugemJS.
This is a basic implementation of routes for "Ferrugemjs", please feel free to do merge requests and improve this router or create your own. This router is implemented using page.js.
clone skeleton-typescript (recomended way)
npm install ferrugemjs-router --save
in config.js.
"ferrugemjs-router":"node_modules/ferrugemjs-router/dist/router"
eg. init-app.html file
<template no-model>
<require from="ferrugemjs-router as rt" type="namespace"/>
<div>
<rt:router-view>
<route path="/list-modules" view="apps/module-list"/>
<route path="/module-a/:id" view="apps/module-a"/>
<route path="/module-b/:id" view="apps/module-b"/>
<route path="/module-b/:id/:name" view="apps/module-b"/>
</rt:router-view>
<h1>Router tests</h1>
<p>
<a href="/list-modules">modules</a>
</p>
<p>
<a href="/module-a/1">module-a</a>
</p>
<p>
<a href="/module-b/2">module-b</a>
</p>
<p>
<a href="/module-b/10/ops">change module-b name and id</a>
</p>
</div>
</template>
<rt:router-view hashbang="true">
<route path="/list-modules" view="apps/module-list"/>
</rt:router-view>
<rt:router-redirect path="/list-modules"/>
<rt:router-redirect
path="/list-modules"
timeout="4000"
/>
<rt:router-view base="/home/">
<route path="list-modules" view="apps/module-list"/>
</rt:router-view>
constructor(){
this.routeList = [
{path:"/list-modules",view:"apps/module-list"}
,{path:"/module-a/:id",view:"apps/module-a"}
,{path:"/module-b/:id/:name",view:"apps/module-b"}
];
}
<rt:router-view routes="this.routeList"/>
<script>
_rt.redirect({path:"/module-a/12",timeout:8000});
</script>
<template>
<require from="ferrugemjs-router/index as router-redirect" type="script"/>
<div>
<router-redirect
path="/list-modules"
timeout="3000"
/>
</div>
</template>
<rt:router-view hashbang="true">
<route path="/" redirect="/list-modules"/>
<route path="/list-modules" view="apps/module-list"/>
</rt:router-view>
<rt:router-view hashbang="true">
<route path="/" redirect="/index.html"/>
</rt:router-view>