# vanjs-router

> Simple Frontend Routing Component Based on Van.js.

Latest version **2.1.4** (published 2025-04-14) · 0 weekly downloads

## Install

```sh
npm install vanjs-router
pnpm add vanjs-router
yarn add vanjs-router
bun add vanjs-router
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2025-04-14 |
| First published | 2023-12-11 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | oyps |

## Links

- npm: https://www.npmjs.com/package/vanjs-router
- npm.io page: https://npm.io/package/vanjs-router

## Dependencies (1)

- [vanjs-core](https://npm.io/package/vanjs-core.md) ^1.5.1

## Recent versions

- 2.1.4 (latest) — 2025-04-14
- 2.1.3 — 2025-04-14
- 2.1.2 — 2025-04-14
- 2.1.1 — 2025-04-14
- 2.1.0 — 2024-11-04
- 2.0.8 — 2024-10-24
- 2.0.7 — 2024-08-26
- 2.0.6 — 2024-07-26
- 2.0.5 — 2024-07-26
- 2.0.4 — 2024-07-25
- 2.0.3 — 2024-07-25
- 2.0.2 — 2024-07-25
- 2.0.1 — 2024-07-25
- 2.0.0 — 2024-07-25
- 1.2.3 — 2024-01-10
- … 16 more at https://npm.io/package/vanjs-router/versions

## README

# vanjs-router

Simple Frontend Routing Component Based on Van.js.

This is version 2. For version 1 documentation, please [click here](https://github.com/iuroc/vanjs-router/tree/79b190f56846bef9906de886ddf29f6c62b892db).

## Features

- Supports both string and regex matching.
- Supports setting page display delay.
- Supports configuring events for the first route match (`onFirst`) and subsequent route matches (`onLoad`).
- Implemented using TypeScript.
- Simple API.

## Quick Start

```shell
npm install vanjs-router
```

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.5.2.nomodule.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vanjs-router@v2.1.4/dist/vanjs-router.iife.js"></script>
<script>
  const { Route, goto } = router;
  const { a, p, div, button } = van.tags;

  const Home = () =>
    Route({
      rule: "home",
      Loader() {
        return div(
          "This Is Home Page.",
          button({ onclick: () => goto("about") }, "Go To About")
        );
      },
      async onFirst() {
        console.log("home onfirst");
      },
      async onLoad() {
        console.log("home onload");
      },
    });

  const About = () =>
    Route({
      rule: "about",
      delayed: true,
      Loader() {
        return div(
          "This Is About Page.",
          button({ onclick: () => goto("home") }, "Go To Home")
        );
      },
      async onLoad() {
        this.show();
      },
    });

  van.add(document.body, Home(), About());
</script>
```

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