2.0.0 • Published 4 years ago

ip-stencil-route-listener v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

IP Stencil Route Listener

Built With Stencil

A simple listener around Stencil router.

Installing

Script tag

  • Put a script tag similar to this <script src='https://unpkg.com/ip-stencil-route-listener@2.0.0/dist/ip-stencil-route-listener.js'></script> in the head of your index.html

In a stencil-starter app

  • Run npm install ip-stencil-route-listener --save
  • Add an import to the npm packages import 'ip-stencil-route-listener';

Using Example

Check out this demo

  @State()
  pageState: string[] = [];

  @Listen('pageEnter')
  onPageEnter(e: CustomEvent<LocationSegments>) {
    this.pageState = [...this.pageState, `Page enter ${e.detail.pathname}`];
  }

  @Listen('pageLeave')
  onPageLeave(e: CustomEvent<LocationSegments>) {
    this.pageState = [...this.pageState, `Page leave ${e.detail.pathname}`];
  }

  render() {
    return (
      <main>
        <stencil-router>
          <stencil-route-switch scrollTopOffset={0}>
            <stencil-route
              url="/"
              component="ip-app-home"
              exact={true}
              // The Magic happens here
              routeRender={props => <ip-stencil-route-listener props={props} />}
            />
            <stencil-route
              url="/about"
              exact={true}
              component="ip-app-about"
              // The Magic happens here
              routeRender={props => <ip-stencil-route-listener props={props} />}
            />
          </stencil-route-switch>
        </stencil-router>
        <ul>
          {this.pageState.map(page => (
            <li>{page}</li>
          ))}
        </ul>
      </main>
    );
  }
2.0.0

4 years ago

0.0.2

5 years ago

0.0.1

6 years ago