npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mfo-router

v0.0.6

Published

Mfo-router, a front-end routing management module.

Downloads

11

Readme

mfo-router

介绍

前端路由管理模块,原生javascript编写router

发行说明

Latest version: npm version

使用

兼容控制

如果你得使用的浏览器不支持 promise (比如 IE),就在 head 中引入:

<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js">
</script>

npm install es6-promise --save

import 'es6-promise/auto'
安装

使用方法:

npm i mfo-router
详细 Demo

全量demo,[index.html]

    <script src="lib/index.js"></script>
    <script>
        const { createRouter } = mfoRouter
        const router = createRouter({
            mode: 'hash',
            routes: [{
                name: 'home',
                path: '/',
                render: () => { console.log('home') }
            }, {
                name: 'user',
                path: '/user',
                render: () => { console.log('user') }
            }]
        })
        router.addRoute({
            name: 'userParams',
            path: '/user-params/id/name',
            render: () => { console.log('userParams') }
        })
        router.addRoute({
            name: 'defaultHome',
            path: '/default-home',
            redirect: '/'
        })
        router.beforeEach((from, to, next) => {
            console.log('[beforeEach]', from, to)
            /* Intercept jump */
            if (from && from.path === '/default-home') {
                next('/user')
            } else {
                next()
            }
        })
        router.afterEach((from, to) => {
            console.log('[afterEach]', from, to)
        })
        router.forceUpdate()
        /* route jump error */
        router.routeJumpErrorFeedBack((err) => console.error(err))
        console.log(router)

        /* button click handle */
        const goHome = () => {
            router.push('/')
        }
        const buttonClickHandle = () => {
            router.push({ path: '/user', query: { a: 1 } })
        }
        const buttonClickHandleD = () => {
            router.push({ path: '/user-params/id/name', params: { id: 1, name: 'nickName' } })
        }
        const buttonClickHandleE = () => {
            router.go(-1)
        }
        const buttonClickHandleF = () => {
            router.replace({ path: '/user-params/id/name', params: { id: 2, name: 'replace' } })
        }
        const buttonClickHandleB = () => {
            router.push({ path: '/default-home' })
        }
        const buttonClickHandleC = () => {
            router.back()
        }
    </script>