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

bare-routes

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-routes

A bare-bones React client-side page router that delegates the actual routing and page loading to user code and only handles history manipulation

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bare-routes

bare-routes is a bare-bones client-side router for React applications. For utmost flexibility, it doesn't provide any means for matching routes, dynamically importing modules, or fetching data. You do all that in your render callback. bare-routes only handles the history API and the scroll position.

Basic usage

The heart of bare-routes is the Router component. It has one required prop, render which is a callback that takes an object argument that contains a property names url, a built-in URL object, and does whatever is necessary for your application to render the new view. Typically it consists of inspecting url.pathname to locate the view module, fetch the required data to render the view component, and render it. render can return either a ReactNode or -more usefully- a promise that resolves to one. Here's a very simple example:

const App = () => (
	<Router
		render={async ({ url }) => {
			try {
				const moduleName = findModuleNameForUrl(url);
				const viewModule = await import(`./view/${moduleName}`);
				const ViewComponent = viewModule.default;
				return <ViewComponent />;
			} catch (error) {
				return <p>Could not load view: {error.message}</p>;
			}
		}}
	>
		Loading...
	</Router>
);

function findModuleNameForUrl(url) {
	// Locate view module for this URL
}

Keywords

FAQs

Package last updated on 10 May 2021

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