Giter Club home page Giter Club logo

history's Introduction

history Travis npm package

history is a JavaScript library that lets you easily manage session history anywhere JavaScript runs. history abstracts away the differences in various environments and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions.

Docs & Help

Installation

Using npm:

$ npm install --save history

Then with a module bundler like webpack, use as you would anything else:

// using an ES6 transpiler, like babel
import { createHistory } from 'history'

// not using an ES6 transpiler
var createHistory = require('history').createHistory

The UMD build is also available on npmcdn:

<script src="https://npmcdn.com/history/umd/history.min.js"></script>

You can find the library on window.History.

Basic Usage

A "history" encapsulates navigation between different screens in your app, and notifies listeners when the current screen changes.

import { createHistory } from 'history'

const history = createHistory()

// Get the current location
const location = history.getCurrentLocation()

// Listen for changes to the current location
const unlisten = history.listen(location => {
  console.log(location.pathname)
})

// Push a new entry onto the history stack
history.push({
  pathname: '/the/path',
  search: '?a=query',

  // Extra location-specific state may be kept in session
  // storage instead of in the URL query string!
  state: { the: 'state' }
})

// When you're finished, stop the listener
unlisten()

You can find many more examples in the documentation!

Thanks

A big thank-you to Dan Shaw for letting us use the history npm package name! Thanks Dan!

Also, thanks to BrowserStack for providing the infrastructure that allows us to run our build in real browsers.

history's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.