Skip to content

Scroll behaviors for use with history, inspired by scroll-behavior

License

Notifications You must be signed in to change notification settings

blackbing/use-scroll-behavior

Repository files navigation

use-scroll-behavior npm package Travis Coveralls

Scroll behaviors for use with history. Inspired by scroll-behavior and simplify the behavior.

Usage

Enhance your history object with this library to get standard scroll behavior after history changed.

import { browserHistory } from 'react-router';
import useScroll from 'use-scroll-behavior';
const history = useScroll(browserHistory);
// ...
export default class App extends Component {
  render() {
    return (
      <Router history={history}>
      //..your routes
      </Router>
    );
  }
}

Guide

Installation

$ npm install history use-scroll-behavior

Config

excludePath: regular Expression Array

set it if you do not want to set scroll position for some path.

const history = scrollBehavior(browserHistory, {
  excludePath: [/news\/id/],
});

TODO

  • add x position?

About

Scroll behaviors for use with history, inspired by scroll-behavior

Resources

License

Stars

Watchers

Forks

Packages

No packages published