Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generouted

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generouted

Generated routes using React Location and Vite

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
increased by123.37%
Maintainers
1
Weekly downloads
 
Created
Source

Generouted

Generated routes using React Location and Vite

Motivation

Vite is a next generation frontend tool and it is very fast, you can't go back xd. After discovering the possibility of accessing local project modules using Vite, I started writing a series about client-side file-based routing with React Router inspired by Next.js. Later I replaced React Router with React Location to support more features like data loaders and nested layouts that are inspired by Remix.

The final version of the series is now published as generouted.

How it works

generouted is only one file that uses Vite APIs to list modules within src/pages/ directory and iterates over them to build the routes passed to React Location.

Why to use it

  • Can be used with any Vite project
  • Declarative and universal file-based routing system
  • Easier to migrated when switching from or to Next.js

Features

  • File-based routing (Next.js conventions)
  • Route-based code-splitting
  • Routes pre-loading
  • Route-based data loaders
  • Nested layouts supporting data loaders

Usage

Installation

npm install generouted
# pnpm add generouted
# yarn add generouted

Setup

With a Vite and React project, render the <Routes /> components from generouted directly or wrap it with other providers/components:

React >= 17
import { render } from 'react-dom'
import { Routes } from 'generouted'

const container = document.getElementById('app')!
render(<Routes />, container)
React 18
import { createRoot } from 'react-dom/client'
import { Routes } from 'generouted'

const container = document.getElementById('app')!
createRoot(container).render(<Routes />)

Adding pages

Add your home page by creating src/pages/index.tsx:

// src/pages/index.tsx

export default function Home() {
  return <h1>Home</h1>
}

Examples

Keywords

FAQs

Package last updated on 09 Apr 2022

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