wuzhi-vue-router

a router library implemented by myself

Usage no npm install needed!

<script type="module">
  import wuzhiVueRouter from 'https://cdn.skypack.dev/wuzhi-vue-router';
</script>

README

routes example

import Vue from "vue";
import WuzhiRouter from "wuzhi-vue-router";
Vue.use(WuzhiRouter);
const Foo = { render(h) { return h('div', ['foo', h('wuzhi-router-view')]) } };
const Bar = { render(h) { return h('div', 'bar') } }
const Hello = { render(h) { return h('div', this.$route.query.hello) } }
const Hi = { render(h) { return h('div', ['hi', h('wuzhi-router-view')]) } };
const Woods = { render(h) { return h('div', this.$route.params.id) } }

const routes = [
    {
        path: '/foo',
        component: Foo,
        children: [
            {
                path: '/hello',
                component: Hello
            },
            {
                path: '/hi',
                component: Hi,
                children: [
                    { path: '/:id', component: Woods }
                ]
            }
        ]
    },
    {
        path: '/bar',
        component: Bar
    }
]
const router = new WuzhiRouter({
    routes
});
export default router

template example

<template>
    <div id="app">
        <wuzhi-router-link to="/foo">foo</wuzhi-router-link>
        <wuzhi-router-link :to="{path: '/foo/hello'}">foo/hello</wuzhi-router-link>
        <wuzhi-router-link :to="{path: '/foo/hi'}">foo/hi</wuzhi-router-link>
        <wuzhi-router-link :to="{path: '/foo/hi/woods'}">foo/hi/woods</wuzhi-router-link>
        <wuzhi-router-link :to="{path: '/bar'}">bar</wuzhi-router-link>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <wuzhi-router-view></wuzhi-router-view>
    </div>
</template>