Because every other router just doesn't cut it anymore.
Find a file
2023-01-23 10:28:23 +01:00
.github workflow 2022-11-01 16:21:50 +01:00
src postNavigation + postNavigationFocus attrs for Router 2023-01-23 10:28:23 +01:00
.gitignore inital 2022-11-01 16:09:01 +01:00
.npmignore updated .npmignore 2022-11-14 21:19:20 +01:00
CHANGELOG.md postNavigation + postNavigationFocus attrs for Router 2023-01-23 10:28:23 +01:00
LICENSE inital 2022-11-01 16:09:01 +01:00
logo.png fixed logo in readme 2022-11-14 21:17:32 +01:00
package.json postNavigation + postNavigationFocus attrs for Router 2023-01-23 10:28:23 +01:00
README.md fixed logo in readme 2022-11-14 21:17:32 +01:00
tsconfig.json basic routing 2022-11-01 17:31:13 +01:00
yarn.lock inital 2022-11-01 16:09:01 +01:00

Logo

React Even Better Router DOM

npm webpage package license npm bundle size

Because every other router just doesn't cut it anymore 🤡

Motivation

Because React sucks and every React Router sucks and everything sucks and being a web developer is a worse crime than attempted murder at this point.

Install

yarn add react-even-better-router-dom

Usage

Basic

import { Router, makeRoutes } from 'react-even-better-router-dom';

function Home() {
	return (
		<h1>Home</h1>
	);
}

function Test() {
	return (
		<h1>Test</h1>
	);
}

function NotFound() {
	return (
		<span>404 not found</span>
	);
}

const ROUTES = makeRoutes({
	'': Home,
	'/test': Test,
});

function App() {
	return (
		<div>
			<Router
				routes={ ROUTES }
				fallback={ NotFound }
			/>
		</div>
	);
}

Dynamic routes

import { Router, makeRoutes } from 'react-even-better-router-dom';
import type { RouteComponentProps } from 'react-even-better-router-dom';

function Home() {
	return (
		<h1>Home</h1>
	);
}

function Project(props: RouteComponentProps) {
	const project = props.match.project;

	return (
		<h1>Project ID: { project }</h1>
	);
}

function NotFound() {
	return (
		<span>404 not found</span>
	);
}

const ROUTES = makeRoutes({
	'': Home,
	// `(\\d+)` is used to only parse integer values
	'/project/:project(\\d+)': Project,
});

function App() {
	return (
		<div>
			<Router
				routes={ ROUTES }
				fallback={ NotFound }
			/>
		</div>
	);
}

Lazy Loading

import { Router, makeRoutes } from 'react-even-better-router-dom';

// Lazy imports to only load the current page when it's actually needed
// The Router component will automagically wrap your component in a <Suspense> component
const Home = lazy(() => import('./pages/Home'));
const Test = lazy(() => import('./pages/About'));

function NotFound() {
	return (
		<span>404 not found</span>
	);
}

const ROUTES = makeRoutes({
	'': Home,
	'/test': Test,
});

function App() {
	return (
		<div>
			<Router
				routes={ ROUTES }
				fallback={ NotFound }
			/>
		</div>
	);
}

Navigating to different routes

import { Router, Link, makeRoutes } from 'react-even-better-router-dom';

function Home() {
	// A RouteCollection has a helper function called 'url'. 
	// This takes a FunctionComponent as an argument.
	// It returns a string to the route of the given component.
	const href = ROUTES.url(Test);

	return (
		<div>
			<h1>Home</h1>
			<Link href={ href }>Go to test page</Link>
		</div>
	);
}

function Test() {
	return (
		<h1>Test</h1>
	);
}

function NotFound() {
	return (
		<span>404 not found</span>
	);
}

const ROUTES = makeRoutes({
	'': Home,
	'/test': Test,
});

function App() {
	return (
		<div>
			<Router
				routes={ ROUTES }
				fallback={ NotFound }
			/>
		</div>
	);
}

Types

The project is made in TypeScript, hope this tells you enough.

Contributing

Just don't