Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raulil/reitintin
Simple router for single-page applications
https://github.com/raulil/reitintin
router
Last synced: about 4 hours ago
JSON representation
Simple router for single-page applications
- Host: GitHub
- URL: https://github.com/raulil/reitintin
- Owner: RauliL
- License: mit
- Created: 2019-11-12T22:29:10.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-10T09:42:51.000Z (about 1 month ago)
- Last Synced: 2024-11-08T16:53:57.415Z (7 days ago)
- Topics: router
- Language: HTML
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rei Tin Tin
Rei Tin Tin is a minimalistic router for single-page applications which uses
fragment portion of the URL to display content.## Usage
Quick usage example below. See file `example.html` for more detailed one.
```JavaScript
import ReiTinTin from 'reitintin';const renderHomePage = () => {
const element = document.createElement('div');...
return element;
};const renderAboutPage = () => {
const element = document.createElement('div');...
return element;
};ReiTinTin()
.route('', renderHomePage)
.route('about', renderAboutPage)
.install(document.querySelector('#root'));
```### ReiTinTin()
Constructs and returns a new router configuration.
### route( path, callback )
Registers new route which uses given callback function to render contents for
that path. [path-to-regexp] is used for path matching (same as is used in
[Express.js]) and any path parameters are passed to the callback function as
arguments.Any [HTMLElement] returned by the callback function will be used as contents
to be displayed, when user navigates to the path. If the callback function
returns either `null` or `undefined`, the container element will be just
cleared and no content will be displayed.If asterisk (`*`) is given as path, the route will be treated as fallback route
which will be used if user navigates to a path that doesn't otherwise exist.### install( container )
Installs the router so that it listens for URL hash changes and renders
contents to given container element.### uninstall()
Removes the URL hash listener so that the router will no longer be used.
[path-to-regexp]: https://github.com/pillarjs/path-to-regexp
[Express.js]: https://expressjs.com/
[HTMLElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement