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

@xso/router

v0.1.1

Published

Router URL navigation to the XSO framework.

Downloads

6

Readme

@xso/router

Based on the URL of the link used in the browser, this will route to content-related.

It is a very important mechanism for building websites using the XSO framework, it changes the content related to the link without a page refresh.

Changes the link and the content dynamically, preserving the page state and avoiding page refresh.

Works like other implementations found in React, Vue, Angular, Svelte, and more.

Documentation

Here is the official website with the full documentation:

Install

To start playing with XSO COM:

npm install -S @xso/router

But better, is to use the PNPM:

pnpm install @xso/router

Or if you prefer Yarn:

yarn add -S @xso/router

Or even another package manager.

How To Use

Example of the capabilities supported in the XSO router:

App.js

import com from "@xso/com";
import { Router, Route } from "@xso/router";

function Main() {
    this.view(()=> [
        { main: {
            _: [
                { [Router]: {
                    routes: [
                        { [Route]: {
                            path: '/',
                            component: Home
                        } },
                        { [Route]: {
                            path: '/product/{uid}/{name}',
                            component: Product
                        } }
                    ]
                } } // Router
            ]
        } } // Main
    ]);
}

export default com(Main);

Page Component

Here is an example of how to create a page component receiving parameters from the URL:

pages/Product/index.js

import com from "@xso/com";

function Product({route}) {
    this.view(() => [
        { h3: {
            _: `Router Parameters`
        } },
        { p: {
            _: `UID: ${route.params.uid}`
        } },
        { p: {
            _: `Name: ${route.params.name}`
        } }
    ]);
}

export default com(Product);

Navigate

The Navigate component creates a link in the DOM using the <a> element, it is easy to create links in the page and menus.

Here is an example of how to use it:

import com from "@xso/com";
import { Navigate } from "@xso/router";

function Link() {
    this.view(()=> [
        { [Navigate]: {
            to: '/my/page',
            onClick: () => alert('Going to My Page...'),
            _: 'To My Page'
        } }
    ]);
}

export default com(Link);

navigateTo

Using the navigateTo is the way to change the page link programmatically, here is an example:

import com from "@xso/com";
import { navigateTo } from "@xso/router";

function Main() {
    const counter = this.state(0);
    this.changes([counter], () => {
        navigateTo(`/product/${counter.val}`);
    });
    this.view(()=> [
        { a: {
            onClick: ()=> navigateTo('/'),
            _: 'Link to Home'
        } },
        { button: {
            onClick: ()=> counter.$val++,
            _: `Click me! ${counter.val}`,
        } }
    ]);
}

export default com(Main);