
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@push.rocks/smartrouter
Advanced tools
A JavaScript library providing routing capabilities for web applications.
A JavaScript library providing routing capabilities for web applications with support for path parameters, query parameters, and programmatic navigation
To install @push.rocks/smartrouter
, run the following command in your project directory:
pnpm install @push.rocks/smartrouter --save
This will add @push.rocks/smartrouter
to your project's dependencies and enable you to use it within your application.
@push.rocks/smartrouter
provides a versatile routing solution for websites, leveraging modern Web APIs to manipulate browser history and handle URL paths intelligently. Below are examples demonstrating how to use @push.rocks/smartrouter
effectively in a TypeScript project, taking advantage of ESM syntax.
First, ensure you've installed the package as described in the Install section above. Next, import SmartRouter
from @push.rocks/smartrouter
in your application's entry point or any module where routing is required.
import { SmartRouter } from '@push.rocks/smartrouter';
Create an instance of SmartRouter
and optionally provide configuration options. If your application requires debugging information, debug
can be set to true
.
const router = new SmartRouter({
debug: true, // Enables debugging. Optional and false by default.
});
Define your application routes using the on
method, which takes a URL pattern and a handler function. The handler function will be called when the application navigates to a URL that matches the pattern.
router.on('/home', async (routeInfo) => {
console.log('Home route accessed', routeInfo);
// Handle the home route
// You can load a page component, change document title, etc.
});
router.on('/about', async (routeInfo) => {
console.log('About route accessed', routeInfo);
// Handle the about route
});
@push.rocks/smartrouter
supports dynamic path parameters. Define path parameters within your route strings using the :
prefix, and access their values from the routeInfo.params
object in your handler function.
router.on('/user/:userId', async (routeInfo) => {
console.log(`User Profile for ID: ${routeInfo.params.userId}`, routeInfo);
// Load and display user profile based on userId
});
Query parameters can be accessed through the routeInfo.queryParams
object, making it easy to handle complex routing scenarios with optional parameters.
router.on('/search', async (routeInfo) => {
console.log('Search Query:', routeInfo.queryParams.query);
// Perform a search operation using the provided query parameter
});
Navigate programmatically using the pushUrl
method. This method allows you to change the URL without reloading the page, and optionally pass state information.
// Navigate to the about page
router.pushUrl('/about');
// Navigate to a user profile with URL parameters
router.pushUrl('/user/12345');
// Navigate with state data
router.pushUrl('/dashboard', { previousPage: 'home' });
@push.rocks/smartrouter
provides methods for managing URL query parameters, enabling dynamic URL manipulation for filter settings, pagination, and other use cases.
// Set a query parameter (replace by default)
router.queryParams.setQueryParam('key', 'value');
// Set a query parameter with push (adds to history)
router.queryParams.setQueryParam('key', 'value', 'push');
// Get a query parameter
const value = router.queryParams.getQueryParam('key');
// Get all query parameters as an object
const allParams = router.queryParams.getAllAsObject();
// Delete a query parameter
router.queryParams.deleteQueryParam('key');
// Delete with push to history
router.queryParams.deleteQueryParam('key', 'push');
Create sub-routers with a specific base path for modular routing:
// Create a sub-router for admin routes
const adminRouter = router.createSubRouter('/admin');
// Routes will be prefixed with /admin
adminRouter.on('/dashboard', async (routeInfo) => {
// This handles /admin/dashboard
});
adminRouter.on('/users', async (routeInfo) => {
// This handles /admin/users
});
The on
method returns a function that can be used to remove the route:
// Add a route
const removeRoute = router.on('/temporary', async (routeInfo) => {
console.log('Temporary route accessed');
});
// Later, remove the route
removeRoute();
When you're done with a router instance, clean it up properly:
// Destroy the router, removing all event listeners and routes
router.destroy();
This module enables complex routing scenarios, simplifying the handling of navigational logic in modern web applications. By leveraging @push.rocks/smartrouter
, developers can implement detailed routing mechanisms, manipulate browser history thoughtfully, and maintain cleaner URL structures, enhancing the user experience and making web apps more accessible.
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
FAQs
A JavaScript library providing routing capabilities for web applications.
We found that @push.rocks/smartrouter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.