1.1.0 • Published 5 years ago

xadparo-react-subrouter v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

react-subrouter

Links

How to use

  1. SubRouter requires Childrens.
  2. Children should have 'url' and 'Component' properties
  3. ChildrenComponent inherits the 'synthesized url'.
  4. A key is automatically generated inside the SubRouter. You don't have to manipulate the key.

Example of usage

  1. Install
npm install --save xadparo-react-subrouter
  1. Use in react.js
import React, { Component } from 'react'
import { Switch, Link } from 'react-router-dom'
import SubRouter from 'xadparo-react-subrouter'

class TempPage extends Component {
  render() {
    var parentUrl = '/temp'

    return (
      <SubRouter path={ parentUrl }>
        {
          ...[
            { key: 123, value: 'qwe' },
            { key: 456, value: 'asd' },
            { key: 789, value: 'zxc' },
          ].map(obj => {
            var { key, value } = obj
            return {
              { url: key, component: () => value }
            }
          })
        }
      <SubRouter>
    )
  }
}

export default TempPage