@lkspc/react-router-enhancers
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-router-enhancers

Enhancers for react-router v4+, built with React Hooks

NPM

Features

React Router Enhancers export several hooks with their paired components.

useScrollToTop and ScrollToTop

Window scrolls to top when pathname changes.

useScrollToTopOnMount and ScrollToTopOnMount

Window scrolls to top when a new route mounted.

useScrollRestoration and ScrollRestoration

Window will scroll to top when a new route mounted and restore previous route's scroll position when navigation back.

Installation

# npm
npm install --save @lkspc/react-router-enhancers

# yarn
yarn add @lkspc/react-router-enhancers

Usage

import React, { Component } from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import { ScrollRestoration } from '@lkspc/react-router-enhancers';

class Example extends Component {
  render() {
    return (
      <BrowserRouter>
        <ScrollRestoration />
        <Switch>
          <Route exact path="/" component={Home} />
          <Route exact path="/about" component={About} />
          <Route exact path="/other" component={Other} />
        </Switch>
      </BrowserRouter>
    );
  }
}

For UmiJS users

// app.js

import { createRouteChange } from '@lkspc/react-router-enhancers';

export const onRouteChange = createRouteChange();

License

MIT © lkspc

Readme

Keywords

none

Package Sidebar

Install

npm i @lkspc/react-router-enhancers

Weekly Downloads

4

Version

1.0.2

License

MIT

Unpacked Size

15.2 kB

Total Files

7

Last publish

Collaborators

  • lkspc