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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pedrovs3/react-router

v1.4.10

Published

This is a simple, lightweight, and flexible routing library for React applications. It provides a set of components and hooks to handle routing in your application, including support for dynamic routes with path parameters.

Downloads

5

Readme

@pedrovs3/react-router

GitHub repo size GitHub language count GitHub forks Github open issues Github open pull requests

Code quality

This is a simple, lightweight, and flexible routing library for React applications. It provides a set of components and hooks to handle routing in your application, including support for dynamic routes with parameters in the URL.

📝 Summary

About the project

This library was created to learn more about how a Router for React works and how to create a library for React. It was inspired by React Router and React Router Dom, however, it has a simpler and more flexible API. In addition, it is lighter and has no external dependencies.

Features and resources

  • [x] Simple API: Just wrap your application with the Router component and use the Route component to define your routes.
  • [x] Dynamic routes: Easily define routes with path parameters, such as "/user/:id". The Route component will automatically extract these parameters and pass them to your component.
  • [x] Query Params: Access the query params of your components with the useRouterContext hook.
  • [x] 404 page: Define a custom 404 page that will be displayed when no route matches.
  • [x] Guarded routes: Define routes that can only be accessed if the user is authenticated.
  • [x] Hooks: It has hooks to access the navigation history and the router context.
  • [x] Metadata: Define metadata for your routes, such as page title and description to improve SEO.
  • [x] Lazy loading: Support for asynchronous loading of components.
  • [x] TypeScript support: All components and hooks are fully typed.
  • [x] Documentation: Complete documentation with usage examples.
  • [x] Lightweight: No external dependencies.
  • [x] Flexible: You can use it with any React project, such as Next.js, Gatsby, etc.
  • [x] Tested: All components and hooks are tested with Jest and React Testing Library.
  • [x] No external dependencies: No external dependencies.

Adjustments and improvements

The project is still under development and future updates will focus on the following tasks:

  • [x] Add support for nested routes.
  • [x] Add support for guarded routes.
  • [ ] Add support for route transitions.
  • [ ] Add support for route prefetching.
  • [ ] Add support for route preloading.

💻 Prerequisites

Before starting, make sure you have met the following requirements:

  • You have installed the latest version of Node.js and npm or yarn or pnpm.
  • You have a <Windows / Linux / Mac> machine.
  • You have created a React project with <create-react-app / Vite>.

🚀 Installing @pedrovs3/react-router

To install @pedrovs3/react-router, follow these steps:

NPM:

npm i @pedrovs3/react-router

YARN:

yarn add @pedrovs3/react-router

PNPM:

pnpm add @pedrovs3/react-router

☕ Using @pedrovs3/react-router

To use the router in your project, follow these steps:

1. Import the Router component and the Route component:

import { Router, Route } from '@pedrovs3/react-router';

2. Wrap your application with the Router component:

import { Router } from '@pedrovs3/react-router';

const App = () => (
  <div className="App">
    <Router>
      {/* Rotas */}
    </Router>
  </div>
);

3. Define your routes with the Route component:

import { Router, Route } from '@pedrovs3/react-router';

const App = () => (
  <div className="App">
    <Router>
      <Route path="/home" component={Home} />
      <Route path="/about" component={About} />
      <Route path="/user/:id" component={User} />
    </Router>
  </div>
);

In the example above, the Home component will be rendered when the user accesses the /home route, the About

4. Using lazy loading:

4.1 Import the lazy function from React:

import { Router, Route } from '@pedrovs3/react-router';
import { lazy } from 'react';

4.2 Import the component you want to load asynchronously:

import { Router, Route } from '@pedrovs3/react-router';
import { lazy } from 'react';

// Example with lazy loading
const About = lazy(() => import('./About'));

4.3 Finally, pass the imported component to the Route component:

import { Router, Route } from '@pedrovs3/react-router';
import { lazy } from 'react';

// Example with lazy loading
const About = lazy(() => import('./About'));

const App = () => (
  <Router>
    <Route path="/home" component={Home} />
    <Route path="/about" component={About} />
    <Route path="/user/:id" component={User} />
  </Router>
);

Router takes care of loading the component asynchronously and rendering it when the user accesses the route.

📫 Contributing

To contribute to @pedrovs3/react-router, follow these steps:

  1. Fork this repository.
  2. Create a branch: git checkout -b <branch_name>.
  3. Make your changes and confirm them: git commit -m '<commit_message>'
  4. Send to the original branch: git push origin <project_name> / <local>

Alternatively, consult the GitHub documentation on how to create a pull request.

🤝 Collaborators

We thank the following developers who contributed:

😄 Be one of the contributors

Want to be part of this project? Click HERE and read how to contribute.

📝 License

This project is under license. See the LICENSE file for more details.

⬆ Back to top