# js-route-resolver

> Route resolver for getting routes by Name

Latest version **0.3.0** (published 2016-12-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install js-route-resolver
pnpm add js-route-resolver
yarn add js-route-resolver
bun add js-route-resolver
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2016-12-03 |
| First published | 2016-11-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ataqu |
| Maintainers | ataqu |
| Keywords | Routes, Resolve, JS, ByName |

## Links

- npm: https://www.npmjs.com/package/js-route-resolver
- Repository: https://github.com/PlumTreeSystems/route-resolver
- Homepage: https://github.com/PlumTreeSystems/route-resolver#readme
- Issues: https://github.com/PlumTreeSystems/route-resolver/issues
- npm.io page: https://npm.io/package/js-route-resolver

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.3.0 (latest) — 2016-12-03
- 0.2.3 — 2016-11-06
- 0.2.2 — 2016-11-06
- 0.2.1 — 2016-11-06
- 0.2.0 — 2016-11-04
- 0.1.3 — 2016-11-04
- 0.1.2 — 2016-11-04
- 0.1.0 — 2016-11-04
- 0.0.4 — 2016-11-04
- 0.0.3 — 2016-11-04
- 0.0.2 — 2016-11-04
- 0.0.1 — 2016-11-04

## README

## Route-resolver

Small module that creates a Javascript class that parses a config file into an Object with keys as **path names** and values as **paths**

## Installation 
```
npm i js-route-resolver 
```
## Getting started

You will need to import in the file 

``` JS
var routeResolverBuilder = require('js-route-resolver');
```
To create the Route resolver you will need to pass a config JS object
``` JS
var RouteResolver = routeResolverBuilder(config);
```
Example config file
``` JS
module.exports =  {
    routes:{
        pathName: {
             value:   "/path/{optionalParameters}",
             defaultParameters:{
                optionalParameters: ":Optional"
             }
        }
    }
}
```
To fetch the path you will need to call the get method
``` JS
// Without parameters
routesResolver.get("pathName");
/*
  The result will be
  "/path"
*/
//With parameters
routesResolver.get('pathName2', {parameter: paramaterValue})
/*
  The result will be
  "/path/paramaterValue"
*/

```
Example of how to use this in a single page React/Redux application

**reducer.jsx**
```JS
import routeResolverBuilder from 'js-route-resolver'
import config from '../configs/routeResolver.config.js'

export const initialState =  routeResolverBuilder(config);

export default function routesReducer(state = initialState, action) {
    switch (action.type) {

        default:
            return state;
    }
}

```
**container.jsx**
```JS
import React from 'react';
import { connect } from 'react-redux';
import Actions from '../actions/actions';
import Widget from '../components/Widget';

const mapStateToProps = (state) => {

    return {
        path_pathName: state.routes.get('pathName'),
        path_pathName2: (id) => state.routes.get('pathName2', {parameter: parameter}),
    };
};

export default connect(mapStateToProps)(Widget);

```
**component.jsx**
```JS
import React, { PropTypes } from 'react';
import { Link } from 'react-router';

export default class Widget extends React.Component {
    render(){
            return (
                <div>
                    <Link to={this.props.path_pathName}>Example Link !</Link> 
                    <Link to={this.props.path_pathName2("Parameter goes here")}>Example Link !</Link> 
                </div>
            );
        }
}
```

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