# vanilla-js-ts-router

> a basic router for a vanila javascript and typescript frontend

Latest version **1.2.5** (published 2024-11-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install vanilla-js-ts-router
pnpm add vanilla-js-ts-router
yarn add vanilla-js-ts-router
bun add vanilla-js-ts-router
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.5 |
| Published | 2024-11-14 |
| First published | 2024-04-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://github.com/KoenMW |
| Maintainers | koenmw |
| Keywords | typescript, router, frontend, vanilla, navigation, routing |

## Links

- npm: https://www.npmjs.com/package/vanilla-js-ts-router
- npm.io page: https://npm.io/package/vanilla-js-ts-router

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.2.5 (latest) — 2024-11-14
- 1.2.4 — 2024-11-14
- 1.2.3 — 2024-11-14
- 1.2.2 — 2024-11-14
- 1.2.1 — 2024-11-14
- 1.2.0 — 2024-10-30
- 1.1.9 — 2024-10-06
- 1.1.8 — 2024-08-10
- 1.1.7 — 2024-08-10
- 1.1.6 — 2024-08-10
- 1.1.5 — 2024-08-10
- 1.1.4 — 2024-08-10
- 1.1.3 — 2024-08-10
- 1.1.2 — 2024-08-10
- 1.1.1 — 2024-08-10
- … 2 more at https://npm.io/package/vanilla-js-ts-router/versions

## README

# Basic Javascript and TypeScript Router

This is a simple router for a vanilla Javascript and TypeScript frontend. It allows you to define routes with associated content, scripts, conditions, and fallbacks.
Can also use search params if you want to use it for something like github pages

## installation

```bash
npm i vanilla-js-ts-router
```

## Usage

```typescript
import router, { setRoutes, getFile } from "basic-ts-router";
// getFile gets our html file from your public folder

const routes: Routes = {
  "/": {
    title: "Home",
    content: getFile("/home.html"),
    scripts: [() => import("./home").then((module) => module.default())], // you can also use the method directly but I prever dinamic importing
    condition: () => true,
    fallback: "/login",
  },
  // ... more routes
};

setRoutes(routes);

router();
```

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