Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BrowserHistory<T>

A BrowserHistory class that implements a doubly linked list.

Example (es imports)

import { BrowserHistory } from 'spectrum-kit';

const history = new BrowserHistory('homepage');

history.visit('page1');
history.visit('page2', 'foo');
history.visit('page3', 'bar');

history.back(1); // => { pathname: 'page2', state: 'foo' }
history.back(1); // => { pathname: 'page1', state: undefined }
history.back(1); // => { pathname: 'homepage', state: undefined }
history.forward(1); // => { pathname: 'page1', state: undefined }
history.forward(1); // => { pathname: 'page2', state: 'foo' }
history.forward(1); // => { pathname: 'page3', state: 'bar' }

Type parameters

  • T

    The type of the value stored in each node

Hierarchy

  • BrowserHistory

Index

Constructors

constructor

Properties

Private _current

Private _root

Methods

back

  • Parameters

    • steps: number

      The number of steps to go back

    Returns ILocationState<T>

    The pathname and state that is the number of steps back from the current page

deserializeHistory

forward

  • Parameters

    • steps: number

      The number of steps to go forward

    Returns ILocationState<T>

    The pathname and state that is steps steps forward from the current page

getCurrentPage

getHomePage

serializeHistory

visit

  • visit(page: string, state?: T): void
  • Parameters

    • page: string

      The page or pathname to visit

    • Optional state: T

    Returns void

Generated using TypeDoc