Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tripolskypetr/react-history-switch

Self-hosted context-free Switch routing component for History.js library (React). The library was created to transfer navigation responsibility from a view into Mobx state container (MVC). Also can be used separately as a self-hosted router
https://github.com/tripolskypetr/react-history-switch

history historyjs link location mobx mvc observable react route router routing search-params switch url-search-params url-search-params-extended

Last synced: about 2 months ago
JSON representation

Self-hosted context-free Switch routing component for History.js library (React). The library was created to transfer navigation responsibility from a view into Mobx state container (MVC). Also can be used separately as a self-hosted router

Awesome Lists containing this project

README

        

# react-history-switch

> Self-hosted context-free Switch component for [History.js](https://www.npmjs.com/package/history) library

## Installation

```bash
npm install --save react-history-switch
```

## Purpose of development

The library was created to transfer navigation responsibility from a view into Mobx state container ([MVC](https://en.wikipedia.org/wiki/Model-view-controller)). Also can be used separately as a self-hosted router

```tsx
import { createObservableHistory } from "mobx-observable-history"

...

const routerService = createObservableHistory();

...

```

## Minimal example

```tsx
import React from 'react';

import { Switch } from 'react-history-switch';
import { createBrowserHistory } from 'history';

const history = createBrowserHistory();

const Link = ({
children,
href,
}) => (

history.push(href)}
>
{children}


);

const HomePage = () => (
<>

Home page



Next page

>
);

const NextPage = ({
param,
}) => (
<>

The next page


{`Param: ${param}`}



Go back

>
);

const NotFound = () => (

Not found


);

/**
* @type import('react-history-switch').ISwitchItem[]
*/
const items = [
{
path: '/',
redirect: '/home',
},
{
path: '/home',
element: HomePage,
},
{
path: '/next/:param',
element: NextPage,
},
];

export const App = () => {
return (

);
};

export default App;
```

## Mobx app example

If you are looking for Mobx MVC example app you should check [this](https://github.com/react-declarative/list-app-mobx) repository

## License

MIT © [tripolskypetr](https://github.com/tripolskypetr)