npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-router-nested

v4.3.2

Published

React Router addon for nesting in for declaring nested paths without knowledge of what was the parent url for current scope.

Downloads

22

Readme

react-router-nested

This library adds nesting to react-router and provides createNav - Nav higher order component wrapper.

NestedRouter

It renders Route component and keeps its all props and renders Router component inside for newly created scope (the route's address).

Props

NestedRouter props are the same as Route component props

Example

import NestedRouter from 'react-router-nested';
import { StaticRouter, Route, Switch, Redirect } from 'react-router-dom';

const App = () => 
    <Switch>
        <NestedRouter path="/settings">
            <Switch>
                <Route path="/general" component={General}/>
                <Route path="/user" component={User}/>
                <Route path="/other" component={Other}/>
                <Redirect to="/general" />
            </Switch>
        </NestedRouter>
        <Route path="/" component={Main}/>
    </Switch>
);

There is also fully working example in example/index.js

Run with webpack dev server at 8080 with: yarn start or npm start

createNav

createNav - Nav higher order component wrapper creating a navigation link from any component.

API

const NavComponent = createNav(NavOptions)(Component);

NavOptions

NavOptions is an optional parameter - it is an object with following keys, all keys are optional.

| Option | Type | Default | Description | |-----------------|:-----------------------:|:---------:|------------------------------------------------------------------------------------| | props | NavPropsOptions | - | Look at table below. | | passedProps | NavPassedPropsOptions | - | Look at table below, | | activeClassName | string or false | false | Class name appended to Component when current url matches prop to¹. | | exact | boolean | false | Use exact match for matching to with current url. | | global | boolean | false | Use global path for matching to with current url. For use with NestedRouter. | | replace | boolean | false | Use use replace instead of push method when changing an url. |

NavPropsOptions

It is an object with following keys, all keys are optional. Props override NavOptions

| Option | Type | Default | Description | |-----------------|:-------------------------------------:|:---------:|--------------------------------------------------------------------------------------------------------------------------------------------------------------| | to | string or (...handlerArgs) => url | false | Property added to Component to provide target url, or function converting handler's arguments (usually it is triggered event) to url to navigate. | | activeClassName | string or false | false | Property added to Component to override NavOptions className appended to Component's when current url matches prop to¹. | | exact | boolean | false | Property added to Component to override NavOptions setting weather to use exact match for matching to with current url. | | global | boolean | false | Property added to Component to override NavOptions setting weather to use global path for matching to with current url. For use with NestedRouter. | | replace | boolean | false | Property added to Component to override NavOptions setting weather to use use replace instead of push method when changing an url. |

NavPassedPropsOptions

These options configure names of properties passed to Component. Property is not passed when set to false. It is an object with following keys, all keys are optional.

| Option | Type | Default | Description | |-------------|:-------------------:|:-----------:|------------------------------------------------------------------------------------------------------------------| | isActive | string or false | false | Name of prop passed to Component providing boolean information about weather current path is active¹. | | currentPath | string or false | false | Name of prop passed to Component providing sting current url. | | handler | string | "onClick" | Name of prop passed to Component with event handler, to trigger url change |

¹Available only when props.to is a prop name (string). It doesn't work when it is configured to resolve url form prop.handler argument.

Example

import { createNav } from 'react-router-nested';
import { StaticRouter } from 'react-router-dom';

const NavBase = (props) => <button {...props} />;
const Nav = createNav({ // default options
    props: {
        activeClassName: false,
        to: 'to',
        global: false,
        replace: false,
        exact: false
    },
    passedProps: {
        handler: 'onClick',
        isActive: false,
        currentPath: false
    },
    activeClassName: false,
    exact: false,
    global: false,
    replace: false
})(NavBase);

const App = () => (
    <StaticRouter context={{}} location='/asd'>
        <Nav to="/zxc" />
    </StaticRouter>
);