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 🙏

© 2025 – Pkg Stats / Ryan Hefner

svelte-cached-router

v1.0.17

Published

A svelte router that could cache the page component and works locally

Downloads

6

Readme

svelte-cached-router

A svelte router that could cache the page component and works locally base on page.js for route and animejs for animation.

screenshot

  1. create a routes.js to define the routes

    // transitions: noAnimation, fade, parallax
    
    export var routes = {
        '/': {
            component: Home,

            // preload funciton: return a Promise and resolve an object
            // the object's key and value will attach to ctx.params 
            // and will set to component's props
            preload: () => {return new Promise.resolve({prop1:, prop2:})},  
            props: {                        // component with props, use default transition

            }
        },
        '/about/:something': {              // something's value use when component create, props
            component: About,
            keepFresh: true,                // recreate everytime
            transition: {                   // transition with props
                type: 'fade',
                params: {
                    scale: 1,
                    duration: 1000
                }
            }
        },
        '/setting': {
            component: Setting,
            transition: 'parallax'          // transition name directly
        }
    }
  1. create Router component instance
<!-- create Router instance and set default transition -->
<Router {routes} transition='parallax' />

page component's props and callback functions

page can be any svelte component, and has some OPTIONAL special properties and callback functions.

The page component will cached by default, if you don't want cache the page you can define a property keepFresh = true then the page will recreate verytime

optional properties and callbacks:

  • props:
    • keepFresh: default is false
  • callbacks:
    • preShow
    • preHide
    • shown
    • hidden

page component exmaple

Home.svelte : the home page component

<div>This is a normal svelte component</div>
<script>

    // this component cache or not
    // true: DO NOT CAHCE THIS PAGE COMPONENT
    export let keepFresh = true;

    export function preShow() {
        console.log('Home page is preShow');
    }

    export function shown() {
        console.log('Home page is shown');
    }

    export function preHide() {
        console.log('Home page is preHide');
    }

    export function hidden() {
        console.log('Home page is hidden')
    }
</script>

access Page.js instance

You can use any page.js funcitions: router.navigate

<Router bind:this={router} {routes} />

<script>
    onMount(() => {
        ...
        // router.navigate = page.js
        router.navigate.show('/abut');
        router.navigate.redirect('/setting')
        ...
    })
</script>

Page transitions

There are three default transitions buildin. fade, parallax and noAnimation default is parallax