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

solidjs-sense-router

v2.1.0

Published

router for solidjs

Downloads

108

Readme

solidjs-sense-router

The SolidJS Router that make sense.

Installation

npm install solidjs-sense-router or yarn add solidjs-sense-router

Why not solid-router

Please take a look at https://github.com/solidjs/solid-router/issues/64 and newBase api of this library

Usage

Sample:

import { Component, lazy } from "solid-js";
import { render } from 'solid-js/web';
import { useRoutes, RouteDefinition } from "solidjs-sense-router";

const routes: RouteDefinition[] = [
  {
    path: "/",
    component: lazy(() => import("./pages/home")),
  },
  {
    path: "/product",
    redirectTo: '/good'
  },
  {
    path: "/good",
    component: lazy(() => import("./pages/good")),
    children: [
      {
        path: "/food",
        component: lazy(() => import("./pages/good/food")),
      },
      {
        path: "/fruit",
        component: lazy(() => import("./pages/good/fruit")),
      },
    ],
    prefetch: true;
    canLoad: () => {
       ...
       return true;
    }
  },
  {
    path: "/news/:id?",
    component: lazy(() => import("./pages/news")),
  },
  {
    path: "/*all",
    component: lazy(() => import("./pages/not-found")),
  },
];

const App: Component = () => {
  const Routes = useRoutes(routes);
  return (
    <Router>
      <Routes />
    </Router>
  );
};

render(() => <App />, document.getElementById('root') as HTMLElement);

API

Components:

  • <Router ...props />

    • props:
      • children: JSX.Element
      • url: current url (must be set in server mode)
      • defaultBase: default base url (default: '')
      • maxKeepAlive: max element for keepAlive, default unlimited
  • <Link ...props />

    • props: same as a tag and more have:
      • replace: if true, replace current url (default: false)
      • state: state object to push in history (default: undefined)
      • queryParams?: Record<string, string> query params
      • activeClass?: class name witch will be added to a tag when link's href is match by current route
      • prefetch?: 'immediate' | 'visible' | 'hover' | 'none'
        • immediate: prefetch when link is rendered
        • visible: prefetch when link is visible
        • hover: prefetch when mouse is over link
        • none: don't prefetch
  • <Outlet /> nest child

  • <KeepAlive ...props /> Keep components alive even after parent's unmounts, saving signals and DOM elements in cache to reuse them. idea from solid-keep-alive

    • props:
      • children: JSX.Element
      • id: unique id for cache
      • onShow call when show
      • onHide call when hide

Hooks:

  • useRoutes(route: RouteDefinition | RouteDefinition[])

    return Routes

  • useLoading(): Accessor<boolean>

    if page is loading

  • useLocation(): { url: Accessor<URL>; fullUrl: Accessor<URL>; base: Accessor<string>; state: Accessor<any>; }

    return url, fullUrl, base, state

  • useNavigator(): { navigate, newBase }

    • navigate(...): navigate to new route
    • newBase(...): change base of url
  • useQueryParams()

    return query params

  • useRouteParams()

    return route params

  • useCurrentMatch(path: string): RouteDefinition | undefined

    return current route match by path

  • useMatch(path: string): RouteDefinition[]

    return route match by path

  • usePrefetch(path: string | string[]): prefetch route match by path

  • useRouteAction(): [Accessor<ActionType>, Accessor<number>] return route action (forward/backward) and current route number which start from 0

    • ActionType: forward | backward current route is forward or backward
  • onRouteLeave((action: ActionType, length: number) => Promise<any>)

    • current route page will unMount until callback's Promise resolve, so you can do some page effects before page leave

Utils:

  • matchRoute(path: string, route: string): { match: boolean; params: Record<string, string> }
    • match: true if path is match by route
    • params: route params match by route