1.2.3 • Published 4 months ago

vanjs-router v1.2.3

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

vanjs-router

Frontend routing control system based on Van.js

Installation

Install van.js and vanjs-router.

npm install vanjs-core vanjs-router
<script src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.2.7.nomodule.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/iuroc/vanjs-router/js/vanjs-router.1.2.2.js"></script>

Import and Usage

import van from 'vanjs-core'
import { Route, routeTo } from 'vanjs-router'

const { button, div } = van.tags

const App = () => {
    return div(
        Route({ name: 'home' },
            'Page Home. ',
            button({ onclick: () => routeTo('about') }, 'Go To About'),
            ' ',
            button({ onclick: () => routeTo('list', ['hot', '15']) }, 'Go To Hot List'),
        ),
        Route({ name: 'about' },
            button({ onclick: () => routeTo('home') }, 'Back To Home'), ' ',
            'Page About.',
        ),
        () => {
            const listType = van.state('')
            const listId = van.state('')
            const welcome = van.state('')
            return Route({
                name: 'list',
                onFirst() {
                    welcome.val = 'Welcome!'
                },
                onLoad(route) {
                    let [type, id] = route.args
                    listType.val = type
                    listId.val = id
                }
            },
                button({ onclick: () => routeTo('home') }, 'Back To Home'), ' ',
                welcome,
                div('List Type: ', listType),
                div('List Id: ', listId),
            )
        }
    )
}

van.add(document.body, App())

Switch Routes

routeTo('home')               // location.hash = ''
routeTo('about')              // location.hash = '#/about'
routeTo('list', ['hot', 15])  // location.hash = '#/list/hot/15'
1.2.0

4 months ago

1.1.9

4 months ago

1.1.8

4 months ago

1.2.3

4 months ago

1.2.2

4 months ago

1.2.1

4 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.1.2

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago