1.8.10 • Published 2 years ago

@joist/router v1.8.10

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

@joist/router

A simple, fairly naive router that can render and views it is given, whether they are JoistElements or not.

Installation:

npm i @joist/di @joist/router @joist/component

Example:

import { component, get, JoistElement } from '@joist/component';
import { template, html } from '@joist/component/lit-html';
import { Route, RouteCtxRef, RouteCtx } from '@joist/router';

import { Child2Element } from './child-2.element';

const routes: Route[] = [
  // Eager component route
  { path: '/foo-1', component: () => document.createElement('child-1') },

  // Eager component route from a CustomElementConstructor
  { path: '/foo-2', component: () => Child1Element },

  // Lazy component route
  { path: '/bar-1', component: () => import('child-2.element').then(() => document.createElement('child-2')) },

  // Lazy component route
  { path: '/bar-2', component: () => import('child-2.element').then(m => m.Child2Element) },

  // Child Paths. Will Match on any router that starts with /child-1
  { path: '/child-1(.*)', component: () => Child1Element  }
];

@component({
  tagName: 'app-root',
  render: template(() => {
    return html`
      <router-link path-match="full">
        <a href="/">Go To Home</a>
      </router-link>

      <router-link>
        <a href="/bar">Go To Bar</a>
      </router-link>

      <router-outlet .routes=${routes}></router-outlet>
    `;
  })
})
export class AppElement extends JoistElement {}


@component({
  tagName: 'child-1',
  render: template(() => {
    return html`
      <h1>Hello From Child 1</h1>

      <router-outlet .routes=${[
        { path: '/child-1/child-2', component: () => Child2Element }
      ]}></router-outlet>
    `
  })
})
class Child1Element extends JoistElement {
  @get(RouteCtx)
  private route: RouteCtx;

  connectedCallback() {
    super.connectedCallback();

    console.log(this.route.value);

    this.route.onChange(ctx => {
      console.log(ctx);
    })
  }
}
1.8.10

2 years ago

1.8.9

2 years ago

1.8.8

3 years ago

1.8.7

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.8.6

3 years ago

1.8.5

3 years ago

1.8.4

3 years ago

1.8.3

3 years ago

1.7.0

3 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.2-canary.0

4 years ago

1.2.1

4 years ago

1.1.4-alpha.0

4 years ago

1.1.4-next.0

4 years ago

1.1.1

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-alpha.30

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.0

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-alpha.29

4 years ago

1.0.0-alpha.27

4 years ago

1.0.0-alpha.28

4 years ago

1.0.0-alpha.23

4 years ago

1.0.0-alpha.22

4 years ago

1.0.0-alpha.25

4 years ago

1.0.0-alpha.24

4 years ago

1.0.0-alpha.21

4 years ago

1.0.0-alpha.20

4 years ago

1.0.0-alpha.19

4 years ago

1.0.0-alpha.17

4 years ago

1.0.0-alpha.16

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.10

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago

1.0.0-alpha.0

4 years ago