# @profiscience/knockout-contrib-router-plugins-with

> [![Version][npm-version-shield]][npm] [![Dependency Status][david-dm-shield]][david-dm] [![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer] [![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev] [![Downloads][npm-stats-shield]][npm-sta

Latest version **2.0.17** (published 2020-10-09) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install @profiscience/knockout-contrib-router-plugins-with
pnpm add @profiscience/knockout-contrib-router-plugins-with
yarn add @profiscience/knockout-contrib-router-plugins-with
bun add @profiscience/knockout-contrib-router-plugins-with
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.17 |
| Published | 2020-10-09 |
| First published | 2018-01-09 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Casey Webb |
| Maintainers | barsh, caseywebb |

## Links

- npm: https://www.npmjs.com/package/@profiscience/knockout-contrib-router-plugins-with
- Repository: https://github.com/Profiscience/knockout-contrib
- Homepage: https://profiscience.github.io/knockout-contrib/packages/router.plugins.with
- Issues: https://github.com/Profiscience/knockout-contrib/issues
- npm.io page: https://npm.io/package/@profiscience/knockout-contrib-router-plugins-with

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0

## Recent versions

- 2.0.17 (latest) — 2020-10-09
- 2.0.0-rc.14 (rc) — 2019-02-19
- 2.0.0-alpha.54341a5d (next) — 2018-07-03
- 2.0.16 — 2020-08-12
- 2.0.15 — 2020-02-04
- 2.0.14 — 2019-12-12
- 2.0.13 — 2019-12-11
- 2.0.12 — 2019-12-11
- 2.0.11 — 2019-12-06
- 2.0.10 — 2019-11-27
- 2.0.9 — 2019-10-22
- 2.0.8 — 2019-08-23
- 2.0.7 — 2019-08-07
- 2.0.6 — 2019-06-13
- 2.0.5 — 2019-06-04
- … 33 more at https://npm.io/package/@profiscience/knockout-contrib-router-plugins-with/versions

## README

# router.plugins.with

[![Version][npm-version-shield]][npm]
[![Dependency Status][david-dm-shield]][david-dm]
[![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer]
[![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev]
[![Downloads][npm-stats-shield]][npm-stats]

[david-dm]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/router.plugins.with
[david-dm-shield]: https://david-dm.org/Profiscience/knockout-contrib/status.svg?path=packages/router.plugins.with
[david-dm-peer]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/router.plugins.with&type=peer
[david-dm-peer-shield]: https://david-dm.org/Profiscience/knockout-contrib/peer-status.svg?path=packages/router.plugins.with
[david-dm-dev]: https://david-dm.org/Profiscience/knockout-contrib?path=packages/router.plugins.with&type=dev
[david-dm-dev-shield]: https://david-dm.org/Profiscience/knockout-contrib/dev-status.svg?path=packages/router.plugins.with
[npm]: https://www.npmjs.com/package/@profiscience/knockout-contrib-router-plugins-with
[npm-version-shield]: https://img.shields.io/npm/v/@profiscience/knockout-contrib-router-plugins-with.svg
[npm-stats]: http://npm-stat.com/charts.html?package=@profiscience/knockout-contrib-router-plugins-with&author=&from=&to=
[npm-stats-shield]: https://img.shields.io/npm/dt/@profiscience/knockout-contrib-router-plugins-with.svg?maxAge=2592000

Allows extending the context for a route with arbitrary data

## Usage

```typescript
import { Route, withRoutePlugin } from '@profiscience/knockout-contrib'

Route.usePlugin(withRoutePlugin)

// Sync
new Route('/', {
  with: {
    myAdditionalProp: true,
  },
})

// Accessor
new Route('/', {
  with: (ctx) => {
    // synchronous
    return {
      myAdditionalProp: true,
    }

    // async via promises
    return Promise.resolve({
      myAdditionalProp: true,
    })
  },
})
```

Now, in the viewModel (as well as any subsequent middleware), `ctx.myAdditionalProp` will be `true`.

**NOTE:** If you're using TypeScript, it's worth noting that the return type _is strongly typed_. The properties it adds _must_
be defined on the IContext interface, _or_ cast as `any`.

e.g.

```typescript
declare module '@profiscience/knockout-contrib-router' {
  interface IContext {
    myAdditionalProp?: boolean
  }
}

// ...or...

new Route('/', {
  with: {
    myAdditionalProp: true,
  } as any,
})
```

---
_Source: https://npm.io/package/@profiscience/knockout-contrib-router-plugins-with · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
