# shared-router

> Shared router for multiple SPA's wriitten in React

Latest version **1.2.1** (published 2020-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install shared-router
pnpm add shared-router
yarn add shared-router
bun add shared-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.2.1 |
| Published | 2020-02-21 |
| First published | 2019-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.9.4 |
| Dependencies | 1 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | artur93gev |
| Maintainers | artur93gev |
| Keywords | router, shared-router, shared history |

## Links

- npm: https://www.npmjs.com/package/shared-router
- Repository: https://github.com/Artur93gev/shared-router
- Homepage: https://github.com/Artur93gev/shared-router#readme
- Issues: https://github.com/Artur93gev/shared-router/issues
- npm.io page: https://npm.io/package/shared-router

## Dependencies (1)

- [history](https://npm.io/package/history.md) ^4.9.0

## 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.1 (latest) — 2020-02-21
- 1.2.0 — 2020-02-21
- 1.1.9 — 2019-09-06
- 1.1.8 — 2019-07-12
- 1.1.7 — 2019-07-12
- 1.0.6 — 2019-07-12
- 1.0.5 — 2019-07-12
- 1.0.4 — 2019-07-11
- 1.0.3 — 2019-07-11
- 1.0.2 — 2019-07-11
- 1.0.1 — 2019-07-11
- 1.0.0 — 2019-07-11

## README

<a href="https://www.npmjs.com/package/shared-router"><img src="https://img.shields.io/badge/npm-shared--router-brightgreen.svg"></a><a href="https://www.npmjs.com/package/shared-router"><img src="https://img.shields.io/npm/v/shared-router.svg"></a>
# shared-router
Router helper for sharing history between applications

# Synopsys

Dilling with large scalable frontend applications causes a lot of problems. The package targets one of those problems: routing. As you know React has no limitation of instances on one window, which can provide a good chance to start with microfrontend architecture. But when more than one application needs routing you have to think about sharing history, same matching routes, etc. `shared-router` package allows you to avoid all this problems.

# Provided API

## setPrefix

```js
@param {prefix} string ['']
```

Setting a prefix for routes for the applications that have been lazyloaded. Each time calling this function will override previous value. NOTE: call this function after the prefixed routes will be rendered.

## createRouteUrl

```js
@param {path} string
```

Use this function each time you initalize a route path. This will automaticly prefix your routes.

## navigate

```js
@param {url} string
@param {isAbsolute} boolean
@param {state} any
```

This function provides an ability to programaticly navigate to needed route. Let's have an `A` application, with routes `routeA` and `routeB`, and also under second route we are loading another application `B`, with its routes `routeC` and `routeD`(NOTE: both applications need to use this package). So the end user must see following routes:

  - routeA
  - routeB/routeC
  - routeB/routeD

Then after calling `setPrefix(routeB)` in the `A` application, you can easly navigate between `B` routes using `navigate('/routeC')` or `navigate('/routeB')`. The following structure is also relaible for application `B` if its standalone, the only difference is that in example case `navigate` function will prefix it with `routeB`, in the other case it will be just the passed argument.

## history

Use this object to manage the browser history. For example you can pass it to the `react-router-dom` `<Router>` for sharing history between applications.

# Playground

Play with example [here](https://codesandbox.io/s/serverless-breeze-tf1u0?fontsize=14&hidenavigation=1&theme=dark)

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