A router plugin for Vivy based on connected-react-router.
npm install vivy-router[npm-image]: https://img.shields.io/npm/v/vivy-router.svg?style=flat-square
[npm-url]: https://npmjs.org/package/vivy-router
[license-image]: https://img.shields.io/npm/l/vivy-router.svg?style=flat-square
[vivy-url]: https://github.com/fatalxiao/vivy
[connected-react-router-url]: https://github.com/supasate/connected-react-router
[with-router-plugin-example-url]: https://github.com/fatalxiao/vivy-router/tree/main/examples/withRouterPlugin
[labor-analgesia-frontend-url]: https://github.com/fatalxiao/labor-analgesia-frontend
[![NPM Version][npm-image]][npm-url]
[![License][license-image]][npm-url]
A [Vivy][vivy-url] plugin to handle router based on [connected-react-router][connected-react-router-url].
* Installation
* Examples
* Examples in repository
* Complete and real project example
* Documentation
* Basic usage
Using npm:
``shell`
$ npm install vivy vivy-router
`shell`
$ cd ./examples/[EXAMPLE_NAME]
$ npm run start
Example names:
* [withRouterPlugin][with-router-plugin-example-url]
* [labor-analgesia-frontend][labor-analgesia-frontend-url]
`js
import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-vivy';
import {createBrowserHistory} from 'history';
import {renderRoutes} from 'react-router-config';
// Import Vivy
import Vivy from 'vivy';
// Import VivyRouter and ConnectedRouter
import VivyRouter, {ConnectedRouter} from 'vivy-router';
// Import component
import Root from 'path_to_your_Root_component';
// Import Vivy model
import yourVivyModel from 'path_to_your_vivy_model';
// Routes config
const routes = [{
path: '/',
component: Root
}];
// Create browser history
const history = createBrowserHistory();
// Create vivy
const vivy = Vivy();
// Apply router plugin
vivy.use(VivyRouter({
history
}));
// Create store after configuration
const store = vivy.createStore();
// Register vivy models
store.registerModel(yourVivyModel);
render(
{renderRoutes(routes)}
document.getElementById('app-container')
);
``