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

@beyond-js/routing

v1.0.0

Published

A versatile client-side routing package for Beyond.js, supporting both hash and pathname modes with seamless navigation and history management.

Downloads

11

Readme

Here is a detailed README.md file for the beyond-js/routing package based on the code provided:

# Beyond.js Routing

The `beyond-js/routing` package is a versatile client-side routing solution designed for modern web applications. It
handles routing modes, URL management, navigation history, and more, all while providing seamless integration for
dynamic web applications.

## Features

-   Supports both `Hash` and `Pathname` routing modes.
-   Automatic handling of URI parsing, query strings, and navigation.
-   Integration with the browser’s history API for smooth state management.
-   Customizable redirection logic.
-   Full event-driven architecture with support for custom events.

## Installation

```bash
npm install @beyond-js/routing
```

Usage

Basic Setup

import { routing } from '@beyond-js/routing';

// Initialize routing
routing.setup();

// Navigate programmatically
routing.pushState('/new-path');

// Listen to routing changes
routing.on('change', () => {
	console.log('Route changed to:', routing.uri.pathname);
});

Routing Modes

The package supports two routing modes:

  1. Hash Mode: URLs are managed using the hash fragment (e.g., http://example.com/#/path).
  2. Pathname Mode: URLs are managed using the path portion (e.g., http://example.com/path).

The routing mode is automatically determined based on the environment and configuration.

// Check the current routing mode
if (routing.mode === RoutingMode.Hash) {
	console.log('Hash mode is active');
}

Programmatic Navigation

You can programmatically navigate within your application using pushState and replaceState.

// Push a new state to the history
routing.pushState('/new-path', { someState: 'example' });

// Replace the current state
routing.replaceState({ anotherState: 'example' }, 'New Title', '/another-path');

Handling Redirects

Custom redirection logic can be implemented by defining the redirect method.

routing.redirect = async uri => {
	if (uri.pathname === '/old-path') {
		return '/new-path'; // Redirect to a new path
	}
};

Backward and Forward Navigation

Control the browser history using back and forward methods.

routing.back(); // Go back in history
routing.forward(); // Go forward in history

API Reference

Routing Class

Properties

  • mode: RoutingMode: The active routing mode (Hash or Pathname).
  • history: BeyondHistory: An instance managing browser history.
  • uri: URI: The current URI being managed by the router.

Methods

  • setup(): Initializes the routing system.
  • pushState(uri: string, state?: object): Pushes a new state to the history and updates the URL.
  • replaceState(state: object, title: string, uri?: string): Replaces the current state and URL.
  • back(): Navigates backward in the history.
  • forward(): Navigates forward in the history.

Events

  • change: Triggered whenever the route changes.

URI Class

The URI class provides an easy way to parse and interact with URLs.

Properties

  • pathname: string: The path part of the URI.
  • search: string: The query string of the URI.
  • qs: QueryString: A parsed map of query parameters.
  • hash: string | undefined: The hash fragment of the URI.

BeyondHistory Class

Manages the history stack and handles the browser’s history API.

Properties

  • current: string: The current URI.
  • position: HistoryPosition: The current position in the history stack.

Methods

  • pushState(uri: string, state: any): Pushes a new state to the browser’s history.
  • replaceState(state: any, title: string, uri: string): Replaces the current state.
  • back(): Moves back in history.
  • forward(): Moves forward in history.

Example Project Structure

src/
│
├── routing.ts           # Main routing logic
├── uri/
│   └── uri.ts           # URI parser and query string handler
└── history/
    ├── history.ts       # Custom history manager
    ├── position.ts      # Tracks the current position in history
    └── records.ts       # Handles the history records

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the MIT License.


This README covers the core functionality and API of the routing package while maintaining clarity for developers looking to integrate it into their projects.