1.0.1 • Published 6 years ago

@lkspc/react-router-scroll v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

react-router-scroll

Scroll manager for react-router v4+, built with React Hooks

NPM JavaScript Style Guide

Features

React Router Scroll exports 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.

Install

npm install --save @lkspc/react-router-scroll

Usage

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

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>
    );
  }
}

License

MIT © lkspc

1.0.1

6 years ago

1.0.0

6 years ago