0.1.3 • Published 5 years ago

@pdehne/mithril-scroll-restoration v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

mithril-scroll-restoration

Scroll restoration for MithrilJS.

Integration

Install the npm package:

$ npm install @pdehne/mithril-scroll-restoration

In your top level JavaScript file import mithril-scroll-restoration and initialize it:

import { initScrollRestoration, ScrollRestoration } from "@pdehne/mithril-scroll-restoration";
...
initScrollRestoration(m);
m.route(document.body, "/", Routes);

Wrap your top level component in the provided ScrollRestoration component, for example:

const Layout = {
  view: vnode => m(ScrollRestoration, [
      m(NavBar),
      vnode.children,
      m(Footer)
  ])
}

Example

See example.html / example.js / example.css for a working example. To run the example clone this repository, open a terminal, cd to the top level folder of the repository and run npm install followed by npm start.