New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-router-cache-route

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-cache-route

cache-route for react-router base on react v16.3+ and router v4+

Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

CacheRoute

Route with cache for react-router like keep-alive in Vue.

Will cache the Route ONLY WHILE GOING FOWARD

Install

npm install react-router-cache-route --save

or

yarn add react-router-cache-route

Usage

Can use CacheRoute, or

Using cacheComponent work with Route's children prop

DO NOT PUT IT IN Switch COMPONENT

import React from 'react'
import { HashRouter as Router, Switch, Route } from 'react-router'
import CacheRoute, { cacheComponent } from 'react-router-cache-route'

import List from './components/List'
import Item from './components/Item'

import List2 from './components/List2'
import Item2 from './components/Item2'

const App = () => (
  <Router>
    <CacheRoute exact path="/list" component={List} />
    <Route exact path="/list2" children={cacheComponent(List2)} />
    <Switch>
      <Route exact path="/item/:id" component={Item} />
      <Route exact path="/item2/:id" component={Item2} />
    </Switch>
  </Router>
)

export default App

Lifecycles

Component with CacheRoute will accept one prop named cacheLifecycles witch contains two functions to inject customer Lifecycle didCache and didRecover

import React, { Component } from 'react'

export default class List extends Component {
  constructor(props, ...args) {
    super(props, ...args)

    props.cacheLifecycles.didCache(this.componentDidCache)
    props.cacheLifecycles.didRecover(this.componentDidRecover)
  }
  
  componentDidCache = () => {
    console.log('List cached')
  }

  componentDidRecover = () => {
    console.log('List recovered')
  }

  render() {
    return (
      // ...
    )
  }
}

Keywords

react-router

FAQs

Package last updated on 26 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts