![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@chanoch/simple-react-router
Advanced tools
Implementation of a simple react router
This is an implementation of Konstantin Tarkus's alternative to react router from You might not need React Router
In Konstantin's system, an array of routes together with the root level 'page' component that will render the root to the router. This array is used with the history component to integrate with the browser's navigation and redux to support navigation through the application.
To create an application using simple-react-router:
import HomePage from './HomePage';
const routes = [
{ path: '/', action: () => <HomePage /> },
{ path: '/index.html', action: () => <HomePage /> },
];
import {SimpleReactRouter} from '@chanoch/simple-react-router';
const router = new SimpleReactRouter(routes);
You can optionally dispatch a state on loading of application data from the server
The Single Page Application's (SPA's) HTML page is a standard react page which contains the following div to mount the application to:
<div id="root"></div>
The HTML page must also include an import for javascript for your application. I use webpack to bundle my JS and dependencies but I import the files statically into the page - can't remember why. There is a webpack mechanism for injecting the scripts into the page at the end of each page.
The reducers, redux middlware, and action creators are all standard redux mechanisms so you will need to define those according to the redux standards.
// Each page component is imported
import MyComponent from './MyComponentPage';
import React from 'react';
// The link between routes or paths in the application are provided in the path property for
// each object in the routes array.
const routes = [
{ path: '/menuplanner/', action: (store) => <MenuPlanner store={store} /> },
{ path: '/menuplanner/selectmenu.html', action: (store) => <ChooseRecipes store={store}/> },
];
export default routes;
A redux reducer modifies the state according to the state change which just occurred. It shouldn't have side-effects.
export function createMealPlanReducer(state, action) {
return {
...state,
mealPlan: action.mealPlan,
action: CREATE_MEAL_PLAN
}
}
FAQs
A simple react router
The npm package @chanoch/simple-react-router receives a total of 1 weekly downloads. As such, @chanoch/simple-react-router popularity was classified as not popular.
We found that @chanoch/simple-react-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.