Socket
Book a DemoInstallSign in
Socket

@roussos/pathway-router

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roussos/pathway-router

A lightweight client-side router that manages navigation, history, caching, and rendering of content within a container element.

latest
Source
npmnpm
Version
0.4.5
Version published
Weekly downloads
16
33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Pathway Router

A lightweight client-side router that manages navigation, history, caching, and rendering of content within a container element.

This is an asynchronous vanilla JS router, simulating the AJAX process, but with some improvements. Inspired by the PJAX Router.

Options

Configuration options for the Pathway router.

OptionTypeDefaultDescription
containerSelectorstring'body'CSS selector for the content container.
defaultLinkSelectorstring'a'CSS selector for valid links.
preloadLinkSelectorstring'[data-preload-link]'CSS selector for links to preload.
excludeLinkSelectorstring'[data-exclude-link]'CSS selector for links to exclude.
historyStackSizenumber10Maximum number of history entries.
cacheCapacitynumber10Maximum number of pages cached.
transitionDurationnumber0Transition duration in milliseconds.
updateRouterHistorybooleantrueWhether to update browser history.
popstateEventbooleantrueEnable handling of popstate events.
clickEventbooleantrueEnable link click interception.
mutationObserverbooleantrueEnable monitoring DOM mutations.
scrollRestorationbooleanfalseRestore scroll position on navigation.
onNavigateOnNavigateCallbackfunction () {}Called before navigation.
onLoadingChangeOnLoadingChangeCallbackfunction () {}Called on loading state changes.
onBeforeLeaveOnBeforeLeaveCallbackfunction () {}Called before leaving a page.
onBeforeRenderOnBeforeRenderCallbackfunction () {}Called before rendering content.
onAfterRenderOnAfterRenderCallbackfunction () {}Called after rendering content.
onErrorOnErrorCallbackfunction () {}Called on navigation/rendering error.

Callbacks

These callbacks allow you to hook into the lifecycle of navigation and rendering.

OnLoadingChangeCallback

Called when loading state changes.

(router: Pathway, state: boolean) => void
  • router: The active Pathway instance.
  • state: true if loading, false otherwise.

OnNavigateCallback

Called before navigating to a new URL.

(router: Pathway, url: string) => void

OnBeforeLeaveCallback

Called before leaving the current page.

(router: Pathway) => void

OnBeforeRenderCallback

Called before rendering new content.

(router: Pathway) => void

OnAfterRenderCallback

Called after rendering new content.

(router: Pathway) => void

OnErrorCallback

Called when a navigation or rendering error occurs.

(router: Pathway, error: ErrorEvent) => void

Example

const router = new Pathway({
  containerSelector: "#app",
  excludeLinkSelector: "a.external, a[download]",
  cacheCapacity: 20,
  scrollRestoration: true,

  onNavigate: (router, url) => {
    console.log("Navigating to:", url);
  },
  onAfterRender: (router) => {
    console.log("New content rendered!");
  },
  onError: (router, error) => {
    console.error("Routing error:", error);
  }
});

Keywords

pathway

FAQs

Package last updated on 17 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts