All Projects → insin → React Router Active Component

insin / React Router Active Component

Licence: other
Factory function for React components which are active for a particular React Router route

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Router Active Component

Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+81.03%)
Mutual labels:  react-router, react-component
whatsapp-clone-react
Build a WhatsApp Clone with React JS and FireBase.
Stars: ✭ 38 (-67.24%)
Mutual labels:  react-router, react-component
React Sight
Visualization tool for React, with support for Fiber, Router (v4), and Redux
Stars: ✭ 2,716 (+2241.38%)
Mutual labels:  react-component, react-router
React Router Form
<Form> is to <form> as <Link> is to <a>
Stars: ✭ 58 (-50%)
Mutual labels:  react-component, react-router
React Router Util
Useful components and utilities for working with React Router
Stars: ✭ 320 (+175.86%)
Mutual labels:  react-component, react-router
git-issue-react-electronjs
⚙️. ⚛️. A desktop application created with Electronjs and Reactjs to be cross-platform to manage and track GitHub issues.
Stars: ✭ 21 (-81.9%)
Mutual labels:  react-router, react-component
awesome-web-react
🚀 Awesome Web Based React 🚀 Develop online with React!
Stars: ✭ 31 (-73.28%)
Mutual labels:  react-router, react-component
react-pits
React 中的坑
Stars: ✭ 29 (-75%)
Mutual labels:  react-router, react-component
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+281.9%)
Mutual labels:  react-component, react-router
React Router Ga
Google Analytics component for React Router
Stars: ✭ 66 (-43.1%)
Mutual labels:  react-component, react-router
React Image Fallback
stop displaying broken images, have another image to fallback on.
Stars: ✭ 106 (-8.62%)
Mutual labels:  react-component
React Color
🎨 Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more
Stars: ✭ 10,287 (+8768.1%)
Mutual labels:  react-component
Rrc
React Router v4 helper components
Stars: ✭ 112 (-3.45%)
Mutual labels:  react-router
React Redux Starter
A basic template that consists of the essential elements that are required to start building a Single Page Application using React, React Router, Redux, Bootstrap 4, Sass, and Webpack
Stars: ✭ 116 (+0%)
Mutual labels:  react-router
Tagify
🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
Stars: ✭ 2,305 (+1887.07%)
Mutual labels:  react-component
React Flow Editor
React component which enables creating flow editors with ease
Stars: ✭ 110 (-5.17%)
Mutual labels:  react-component
Mirror
A simple and powerful React framework with minimal API and zero boilerplate.
Stars: ✭ 1,445 (+1145.69%)
Mutual labels:  react-router
Dva Boot Admin
🍰 react admin dashboard ui LANIF-ADMIN --- react 16 + react-router 4 + dva 2 + antd 4 后台管理 脚手架
Stars: ✭ 1,553 (+1238.79%)
Mutual labels:  react-router
React Login
A client side implementation of authentication using react.js for my blog on medium. This is the second part of my previous blog on how to implement scalable node.js server.
Stars: ✭ 105 (-9.48%)
Mutual labels:  react-router
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (+0%)
Mutual labels:  react-router

React Router Active Component

Travis Codecov npm package

A factory function for creating React components which get a special className when a specified React Router route is active, and can also handle creating a link to the route.

The primary use case for this module is making it convenient to create components which contain a link to a route but put the active class name on the container rather than the link:

Using React Router's Link component:

<ul>                                      <ul>
  <li>                                      <li>
    <Link to="/route"                 =>      <a href="/route" class="active">
          activeClassName="active">             Link Text
      Link Text

Using the activeComponent() factory function:

var NavLink = activeComponent('li')
<ul>                           <ul>
  <NavLink to="/route">   =>     <li class="active">
    Link Text                      <a href="/route">
                                     Link Text

Live Demo (source)

The demo shows:

  • A NavLink component which creates a navigation <li> (including its <a>) which gets an "active" class, as required by Bootstrap's CSS.

    var NavLink = activeComponent('li')
    
  • An ActivePara component which creates a <p> which only gets a "special" class for a specific route.

    var ActivePara = activeComponent('p', {link: false})
    
    <ActivePara to="/path/to" activeClassName="special">...</ActivePara>
    

Install

npm install react-router-active-component
import activeComponent from 'react-router-active-component'
// or
var activeComponent = require('react-router-active-component')

API

activeComponent(component[, options])

Creates a ReactComponent which takes the same props as React Router's Link component to configure when it is considered active and which class it will be given when active.

The component's contents will be wrapped in the given tag name or component - by default, its children will be used as contents for a <Link/>.

component: String | ReactComponent

This can be anything that can be passed as the first argument to React.createElement() - a tag name string or a ReactComponent which will be used to wrap the component's children.

var NavItem = activeComponent('li')

If a custom React component is given, the following additional props will be passed to it when rendering:

  • active: Boolean - true if the specified route is active, false otherwise.
  • className: String - contains any className passed to the component plus its activeClassName, if active.
  • style: Object - the activeStyle object passed to the component, if active.
options: Object

An options object with the following properties:

link: Boolean (default: true)

If true, the component's props and children be used to create a <Link/>. Otherwise, its children will just be wrapped in the specified component.

var ActiveParagraph = activeComponent('p', {link: false})
linkClassName : String

A default className for the nested <Link/>.

Component Props

The component created by activeComponent() takes the same props as React Router's Link component. See the React Router Link API docs for details.

One difference is that activeClassName will default to active if not provided, since determining if a component is active is the whole point of using activeComponent()!

Use the onlyActiveOnIndex boolean prop to control when a component is considered active when its URL path matches part of a deeper path - for example, if you have a "Home" navigation link which you only want to display as active when the current path is '/', you should use this prop:

<NavLink to="/" onlyActiveOnIndex>Home</NavLink>
<NavLink to="/tasks">Tasks</NavLink>

Pass a linkProps object to provide additional props when rendering a nested <Link/>:

<NavLink to="/special" linkProps={{className: 'special', onClick: this.handleSpecial}}>
  Special Link
</NavLink>

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].