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-pathfy

v0.1.4

Published

A very simple to install and use router tool for React and ReactNative

Downloads

21

Readme

React-Pathfy

Probably the simplest router for React applications you will find.

Instalation

npm i --save react-pathfy

Guide

To use React-Pathfy you have to set its routing elements as parents of the other elements in your application.

React-Pathfy has two routing elements Root and Path. Root must be the top most element in your elements tree. It receives Path elements as children. Path elements may contain other Path.

import React, { Component } from 'react';
import { Root, Path } from 'react-pathfy';
import MyComponent from './components/MyComponent';
import NotFound from './components/NotFound';

class App extends Component {
  render() {
    return (
      <Root mode='browser'>
        <Path origin="/hello" component={ <h1>Hello World</h1> } />
        <Path origin="/some">
          <Path origin="/path" component={ MyComponent } />
        </Path>
        <Path notFound={ true } component={ NotFound } />
      </Root>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));

Root

Defines the root of all paths.

props

mode: the mode React-Pathfy must use. The available options are browser, hash and memory. You should use the memory mode when you are developing a ReactNative app or an application that doesn't rely on URLs. Defaults to browser.

Path

Defines each path of an application. Every path must have a component associated. Path elements can be nested. The inner elements will be passed as children to their parents. All Path elements in a path tree will receive the pathfy props.

props

origin: the URL or key of a path. The URLs are combined if the Path elements are nested.

component: the component to be rendered.

notFound: A boolean value that defines a path to be used when no other paths respond to a request.

Link

Defines a link element that changes the current path.

import { Link } from 'react-pathfy';
render(){
  return (
    <Link to={ '/payment' } state={ {type: 'credit-card'} } />
  )
}

props

to: the URL or key of the target path.

state: the data to be passed to the rendered component

origin

The origin defines the URL pattern or the key of the path. When the path responds to a URL, wildcards can be used to capture parameters.

/something/:parameter1

/something/:parameter1/(:parameter2)

In the first example above, :parameter1 defines a mandatory parameter. In the second example, (:parameter2) defines an optional parameter.

All origin parameters can be accessed by props.pathfy.params

props.pathfy

When a component is rendered it receives a pathfy props that has relevant resources to be used.

properties

action: The action that drove to that path. The possible values are INITIAL, PUSH, POP, REPLACE

state: The data passed when using the Link element.

origin: the current origin.

history: the global active history object.

params: the parameters in the URL.

query: an object representing the query string.

history

It is the most important dependency of React-Pathfy. Check the docs at https://www.npmjs.com/package/history

You can require the active history object from the react-pathfy module and use it, for example, in a Redux reducer.

import { history } from 'react-pathfy'

To change the current path you would use as following:

history.push('/some-path')

TODO

  • Middlewares
  • Force default route