New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pojo-router/core

Package Overview
Dependencies
Maintainers
4
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pojo-router/core

A React hooks library to associate metadata to a path

  • 0.10.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
72
decreased by-29.41%
Maintainers
4
Weekly downloads
 
Created
Source

pojo-router

npm downloads bundle size npm version PRs Welcome

A hook based machanism to convert a string (i.e. a path) into metadata.

API

Define your metadata in a provider component.

import React from 'react';
import PojoRouter from 'pojo-router';

const namedPaths = {
  page1: '/page1',
  page2: { path: '/page2', sensitive: true },
  page3: { path: '/page3/:id' },
};

const routes = [
  { name: 'page1', abc: 123 },
  { name: 'page2', abc: 456 },
  { name: 'page3', abc: 789 },
  { name: '/page4', abc: 0 }
];

const notFound = { nothing: true };

const Router = ({ children }) => (
  <PojoRouter namedPaths={namedPaths} routes={routes} notFound={notFound}>
    { children }
  </PojoRouter>
);

Controller

type Props = {
    namedPaths: Record<string, string | NamedPath>;
    routes: readonly Route[];
    notFound: AnyIfEmpty<DefaultRoutePojo>;
};

class RouteController {
    constructor({ namedPaths, routes, notFound }: Props);

    readonly notFound: AnyIfEmpty<DefaultRoutePojo>;
    readonly pathBuilders: Record<string, PathFunction>;
    getMatchedRoutes(pathToMatch: string): any;
    buildPath(pathOrPathName: string, pathData?: object): void;
}

notFound

This is the passed in notFound object.

getMatchedRoutes(pathToMatch)

Gets all routes matching the passed path.

buildPath(pathOrPathName, pathData)

Given a named route (or route string if none is defined), this returns a function that will generate a matching string, including populating the dynamic variables. E.g. for a route like /entity/:id an outbound routing function like entityPath({ id: 123 }) will generate /entity/123.

controller.buildPath('entity', { id: 123 })

Hooks

Within your child component, use one of the hooks.

useRoutes()

Given a path, this returns all the metadata for routes that match.

useLocation()

Get current location

useRouter()

Return the RouteController that can be used for computations

Keywords

FAQs

Package last updated on 25 Jan 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc