0.0.2 • Published 1 year ago

ts-routing-service v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

TS Routing Service

This liabrary provides two very basic functions: routingHandler and handleNavigation. They are 'framework' agnostic and have been tested in React and Vue.

routingHandler

The routingHandler function allows you to set up a callback that will be executed whenever the route changes in your web application. It monitors changes in the browser's location and triggers the callback with the current route and query parameters whenever the browser's back or forward button is pressed.

import { routingHandler } from 'ts-routing-service;

const callback = (currentRoute, queryParams) => {

    console.log('Current Route:', currentRoute);
    console.log('Query Parameters:', queryParams);

};

routingHandler(callback);`

handleNavigation

The handleNavigation function simplifies the process of changing the URL in the browser's address bar and dispatching the popstate event. It takes a path and optional query parameters, constructs the URL, updates the browser's history, and dispatches the popstate event, making it suitable for programmatic navigation within your web application.

import { handleNavigation } from 'path-to-module';

handleNavigation('/new-route', { param1: 'value1', param2: 'value2' });