19.0.0 • Published 4 years ago

@erickmerchant/router v19.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

@erickmerchant/router

A module to do routing inside your components. Meant to be used with @erickmerchant/framework. Does not do anything with the history API for you.

Example

/* component.js */

import {router} from '@erickmerchant/router'
import {html} from '@erickmerchant/framework'

const {route, link} = router()

export const component = (state) => html`<body>${
    route(state.location, (on) => {
      on('page/:categories+/:id?', (params) => html`<h1><a href=${link('page/:categories+/:id?', params)}>${`Page ${params.id}`}</a></h1>`)

      on(() => html`<h1>Page Not Found</h1>`)
    })
  }</body>`

Parameters

A route can contain multiple segments separated by slashes. Segments can begin with a colon. Those are replaced by props from the object in the case of link or populate params in the case of on. Colon prefixed segments can have a *, +, or ? modifier at the end, which change whether it is required and whether it consumes multiple segments.

requiredmultiple
:exampletruefalse
:example*falsetrue
:example+truetrue
:example?falsefalse

Light Version

widlcard.mjs provides a more minimal variation.

/* component.js */

import {route, link} from '@erickmerchant/router/wildcard.mjs'
import {html} from '@erickmerchant/framework'

export const component = (state) => html`<body>${
    route(state.location, (on) => {
      on('page/**/*', (categories, id) => html`<h1><a href=${link`page/${categories}/${id}`)}>${`Page ${id}`}</a></h1>`)

      on(() => html`<h1>Page Not Found</h1>`)
    })
  }</body>`
19.0.0

4 years ago

18.2.0

4 years ago

18.1.1

4 years ago

18.1.0

4 years ago

18.0.0

4 years ago

17.5.2

4 years ago

17.5.1

4 years ago

17.5.0

5 years ago

17.4.0

5 years ago

17.3.7

5 years ago

17.3.6

5 years ago

17.3.5

5 years ago

17.3.4

5 years ago

17.3.3

5 years ago

17.3.2

5 years ago

17.3.1

5 years ago

17.3.0

5 years ago

17.2.1

5 years ago

17.2.0

5 years ago

17.1.0

5 years ago

17.0.0

5 years ago

16.0.0

5 years ago

15.1.7-1

5 years ago

15.1.7-0

5 years ago

15.1.6

6 years ago

15.1.5

6 years ago

15.1.4

6 years ago

15.1.3

6 years ago

15.1.2

6 years ago

15.1.1

6 years ago

15.1.0

6 years ago

15.0.3

6 years ago

15.0.2

6 years ago

15.0.1

6 years ago

15.0.0

6 years ago

14.2.3

6 years ago

14.2.2

6 years ago

14.2.1

6 years ago

14.2.0

6 years ago

14.1.3

7 years ago

14.1.2

7 years ago

14.1.1

7 years ago

14.1.0

7 years ago

14.0.1

7 years ago

14.0.0

7 years ago

13.0.1

7 years ago

13.0.0

7 years ago

12.0.5

7 years ago

12.0.4

7 years ago

12.0.3

7 years ago

12.0.2

7 years ago

12.0.1

7 years ago

12.0.0

7 years ago

11.0.1

7 years ago

11.0.0

7 years ago

10.1.1

7 years ago

10.1.0

7 years ago

10.0.0

7 years ago

9.5.0

7 years ago

9.4.2

7 years ago

9.4.1

7 years ago

9.4.0

7 years ago

9.3.0

7 years ago

9.2.1

7 years ago

9.2.0

7 years ago

9.1.0

8 years ago

9.0.0

8 years ago

8.0.2

8 years ago

8.0.1

8 years ago

8.0.0

8 years ago

7.0.0

8 years ago

6.0.2

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.0.0

8 years ago

4.11.0

8 years ago

4.10.0

8 years ago

4.9.0

8 years ago

4.8.0

8 years ago

4.7.0

8 years ago

4.6.0

8 years ago

4.5.0

8 years ago

4.4.0

8 years ago

4.3.0

8 years ago

4.2.0

8 years ago

4.1.0

8 years ago

4.0.0

8 years ago

3.0.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago