# @satachito/jp-router

> A simple WebComponents router

Latest version **1.0.4** (published 2020-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @satachito/jp-router
pnpm add @satachito/jp-router
yarn add @satachito/jp-router
bun add @satachito/jp-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-09-11 |
| First published | 2020-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Satoru Ogura |
| Maintainers | satachito |

## Links

- npm: https://www.npmjs.com/package/@satachito/jp-router
- Repository: https://github.com/Satachito/jp-router
- Homepage: https://github.com/Satachito/jp-router#readme
- Issues: https://github.com/Satachito/jp-router/issues
- npm.io page: https://npm.io/package/@satachito/jp-router

## Recent versions

- 1.0.4 (latest) — 2020-09-11
- 1.0.3 — 2020-09-11
- 1.0.2 — 2020-09-11
- 1.0.1 — 2020-05-08
- 1.0.0 — 2020-05-08
- 0.9.5 — 2020-05-08
- 0.9.1 — 2020-05-08
- 0.9.0 — 2020-05-08

## README

# jp-router

A small and understandable WebComponets router which supports:

* Lazy loading
* Direct html
* Tag base creation

## Install

```
npm install @satachito/jp-router --save
```

## Demo

Our demo contains various patter including illegal patterns i.e. 404 and multiple routing.

see https://satachito.github.io/jp-router/

## Write HTML and JavaScript

### index.html
```
<!DOCTYPE html>
<html lang=zxx>
<meta charset="utf-8" />
<title>Router</title>

<script type=module>
	class
	Home extends HTMLElement {
		connectedCallback() {
			this.innerHTML = '<h1>Home</h1>'
		}
	}
	customElements.define( 'jp-home', Home )
</script>

<nav class=nav>
	<ul>
		<li route=/				>Home			</li>
		<li route=/direct		>Direct HTML	</li>
		<li route=/horses		>Horses			</li>
	</ul>
</nav>

<jp-route
	path=/
	title=Home
	data=jp-home
	spec=tag
></jp-route>

<jp-route
	path=/direct
	title="Direct html"
	data="<b>DIRECT HTML</b>"
	spec=html
></jp-route>

<jp-route
	path=/horses
	title=Horses
	data=/horses.js
	spec=source
></jp-route>

<jp-route
	path=/horse/:id
	title="Horse Details"
	data=/horse.js
	spec=source
></jp-route>

<script type=module src=./node_modules/@satachito/jp-router/jp-router.js></script>
<jp-router></jp-router>
```

### horseDB.js

```
export default [
	[ 'Narita Brian'	, 19910503 ]
,	[ 'Deep Impact'		, 20020325 ]
,	[ 'Orfevre'			, 20080514 ]
]
```

### horses.js
```
import horseDB from './horseDB.js'

export default class
Horses extends HTMLElement {
	connectedCallback() {
		this.innerHTML = `
			<h1>Horses</h1>
			<ul>
				${ horseDB.map( ( $, _ ) => `<li route=/horse/${ _ }>${ JSON.stringify( $ ) }</li>` ).join( '' ) }
			</ul>
		`
	}
}

customElements.define( 'jp-horses', Horses )
```

### horse.js

```
import horseDB from './horseDB.js'

export default class
Horse extends HTMLElement {
	connectedCallback() {
		this.innerHTML = `
			<h1>Horse Details</h1>
			<div>${ JSON.stringify( horseDB[ this.getAttribute( 'id' ) ] ) }</div>
		`
	}
}

customElements.define( 'jp-horse', Horse )
```

### Serve

```
npm install -g http-server
http-server
```

---
_Source: https://npm.io/package/@satachito/jp-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
