Socket
Book a DemoInstallSign in
Socket

@idrinth-api-bench/react-file-based-routes

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@idrinth-api-bench/react-file-based-routes

A simple file based routing library, that does not force itself on you.

latest
Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

@idrinth/react-file-based-routes

This is a small library used to teach the default react routers file based routing and optimise the output as far as that is possible without server side rendering. It is meant for mostly static pages, where the overhead of nextjs of vike is not required.

Defining a page

A page is by default any ìndex.tsx within the src/pages folder. The folder name will be taken as the page url, with two exceptions by default:

  • home will be the root
  • not-found will be the 404 page

Configuration

All rules can be configured in an .idrinth-react-file-based-routes.json file, options are currently:

interface Configuration {
  sitemap?: {
    domain?: string,
    build?: boolean,
  },
  runtime?: {
    reloadWaitMs: number
  },
  routes?: {
    build?: boolean,
    type?: 'tsx'|'jsx',
    overridePathMappings?: {
      [filesystemPath: string]: string,
    },
  },
  htmlMinify?: {
    collapseBooleanAttributes?: boolean,
    conservativeCollapse?: boolean,
    collapseWhitespace?: boolean,
    removeAttributeQuotes?: boolean,
    removeComments?: boolean,
  },
  fileBuilder?: {
    buildIndex?: boolean,
    minifyPages?: boolean,
    appendPageChunk?: boolean,
    preLoadCSS?: boolean,
    preloadStartDelay?: number,
  },
  fileFinder?: {
    fileName?: string,
    pagesRoot?: string,
    distJSRoot?: string,
  },
}

If you prefer using a cli format, --{group}.{setting}=abc will set string settings to abc, while booleans can be flipped by just using --{group}.{setting}. For example for api-bench, that uses the defaults, you can set the domain by using --sitemap.domain=idrinth-api-ben.ch. The setting fileFinder.overridePathMappings can not be configured via the cli.

Default options are overwritten first by the file based settings and then by the command line settings.

Setup

You will need to do three things for the complete package:

  • Define a call to generate-routes(irfbrgr or react-file-based-routes-generate-routes) in you package.json as afterInstall and early in your build process to generate the routes.tsx and the sitemap
  • Optionally define a call to generate-folders(ìrfbrgf or react-file-based-routes-generate-folders) in your package.json as a late build step to optimise the index.html files
  • Default import the generated src/routes.tsx, so that you can use createBrowserRouter or similar functions to create your router. It requires getting a Loader element passed to it - any react element will do

Keywords

react

FAQs

Package last updated on 26 May 2024

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