All Projects → xvw → Jsoo_router

xvw / Jsoo_router

Licence: gpl-3.0
A small router to write easily single-page-app in Js_of_ocaml

Programming Languages

javascript
184084 projects - #8 most used programming language
ocaml
1615 projects

Projects that are alternatives of or similar to Jsoo router

Webvr Webpack Boilerplate
A webvr multi-scenes Single-page application for three.js, webpack
Stars: ✭ 47 (+95.83%)
Mutual labels:  router, spa
React Resource Router
Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering
Stars: ✭ 136 (+466.67%)
Mutual labels:  router, spa
Routegen
Define your API and SPA routes in one place. Use them anywhere. Only 1.3kb.
Stars: ✭ 86 (+258.33%)
Mutual labels:  router, spa
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (+75%)
Mutual labels:  router, spa
Angular
UI-Router for Angular: State-based routing for Angular (v2+)
Stars: ✭ 287 (+1095.83%)
Mutual labels:  router, spa
Sme Router
A lightweight router lib that implement with express route style
Stars: ✭ 112 (+366.67%)
Mutual labels:  router, spa
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+6558.33%)
Mutual labels:  router, spa
Redux Tower
Saga powered routing engine for Redux app.
Stars: ✭ 155 (+545.83%)
Mutual labels:  router, spa
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (+995.83%)
Mutual labels:  router, spa
xRoute
一个小型的前端路由库✈️
Stars: ✭ 36 (+50%)
Mutual labels:  spa, router
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (+1458.33%)
Mutual labels:  router, spa
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (+1100%)
Mutual labels:  router, spa
React
🔼 UI-Router for React
Stars: ✭ 386 (+1508.33%)
Mutual labels:  router, spa
Prerender Spa Plugin
Prerenders static HTML in a single-page application.
Stars: ✭ 7,018 (+29141.67%)
Mutual labels:  spa
Kua
⚡️ Lightning fast URL routing in Python (trie router)
Stars: ✭ 18 (-25%)
Mutual labels:  router
Xunlei Fastdick
迅雷快鸟 Xunlei Network Accelerator For Router
Stars: ✭ 789 (+3187.5%)
Mutual labels:  router
One
一个极简高性能php框架,支持[swoole | php-fpm ]环境
Stars: ✭ 789 (+3187.5%)
Mutual labels:  router
Node
Stampery API for NodeJS. Notarize all your data using the blockchain
Stars: ✭ 23 (-4.17%)
Mutual labels:  hash
Multiprocessrouter
一个多进程路由框架,使用APT处理路由接口的注册和初始化。多个模块间可以进行IPC调用。
Stars: ✭ 18 (-25%)
Mutual labels:  router
Find My Way
A crazy fast HTTP router
Stars: ✭ 776 (+3133.33%)
Mutual labels:  router

This project is an experience and is not maintened

JSOO_Router

Jsoo_router is a tool to facilitate front-end routing. This library uses a syntax extension (ppx).

Jsoo_router is a tool that allows to easily realize single-page-app via a router On the hash ( # url). The library exposes a function to start routing and a syntax extension to use pattern matching to define routes. The documentation of the Router module is available here.

Installation

Use opam install jsoo_router

Use with OCamlfind

Add the flags -package jsoo_router -package jsoo_router.ppx

Watch hash transformation

The module Router expose a start : (unit -> 'a) -> unit function. Router.start f execute f when the hash is changed. For example you can try this code : Router.start (fun () -> alert "changement")

In this code, I'm using alert defined as let alert s = Dom_html.window##alert(Js.string s)

Manage routes

You can match routes using match [%routes] with .... For example :

let () = Router.start (fun () ->
  match [%routes] with
  | "foo" -> alert "Foo's page"
  | "bar" -> alert "Bar's page"
  | ""    -> alert "Index's page"
  | _     -> alert "Unmanaged page"
)

[%route] for complex routes construction

let () = Router.start (fun () ->
  match [%routes] with
  | "foo"                    -> alert "Foo's page"
  | "bar"                    -> alert "Bar's page"
  | ""                       -> alert "Index's page"
  | [%route "foo-(bar|foo)"] -> alert "Using regex"
  | [%route "digit-[0-9]"]   -> alert "Regex with a digit"
  | _                        -> alert "Unmanaged page"
)

Using [%route ...] you can use regex in the route definition.

Routes with variables

You can use [%route "some-{type}-{other-type}"] to define variables into route. Here is the list of available types :

Internals types

  • string
  • int
  • bool
  • char
  • float

Extract variables from the route

Those variables could be extract with the function route_arguments (). This function returns a n-uplet of the all extracted variables in the order of their definition.

  let () = Router.start (fun () ->
      match [%routes] with
      | "foo"                            -> alert "Foo's page"
      | "bar"                            -> alert "Bar's page"
      | [%route "foo-(bar|foo)"]         -> alert "FooBar or FooFoo"
      | [%route "digit-[0-9]"]           -> alert "Regex with a digit"

      | [%route "code-{int}"]            -> (* HERE A DEFINITION WITH JUST AN INT *)
        let code = route_arguments () in
        alert (Printf.sprintf "The code is : %d" code)

      | [%route "people-{string}-{int}"] -> (* HERE A DEFINITION WITH A STRING AND AN INT *)
        let name, age = route_arguments () in
        alert (Printf.sprintf "Hi %s, you are %d !" name age)

          
      | ""                               -> alert "Index's page"
      | _                                -> alert "Unmanaged page"
    )

Examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].