Skip to content

ferrugemjs/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Router to FerrugemJS

Ferrugem router logo

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.

NPM

how to start:

clone skeleton-typescript (recomended way)

individual install

npm install ferrugemjs-router --save

in config.js.

"ferrugemjs-router":"node_modules/ferrugemjs-router/dist/router"

Usage

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>

hashbang

<rt:router-view hashbang="true">
  <route path="/list-modules" view="apps/module-list"/>
</rt:router-view> 

redirect

<rt:router-redirect path="/list-modules"/>

redirect with timeout

<rt:router-redirect 
  path="/list-modules"
  timeout="4000"
/>

base path

<rt:router-view base="/home/">
  <route path="list-modules" view="apps/module-list"/>
</rt:router-view>

dinamic route list

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"/>

redirect from a script tag

<script>
  _rt.redirect({path:"/module-a/12",timeout:8000});
</script>

redirect from a representative function

<template>
  <require from="ferrugemjs-router/index as router-redirect" type="script"/>
  <div>
    <router-redirect 
      path="/list-modules"
      timeout="3000"
    />
  </div>
</template>

redirect from a path to other

<rt:router-view hashbang="true">
  <route path="/" redirect="/list-modules"/>
  <route path="/list-modules" view="apps/module-list"/>
</rt:router-view> 

redirect from "/" to "/index.html"

<rt:router-view hashbang="true">
  <route path="/" redirect="/index.html"/>
</rt:router-view> 

About

a basic router implementation to ferrugemjs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published