Gathering detailed insights and metrics for @leanjs/react-router
Gathering detailed insights and metrics for @leanjs/react-router
Gathering detailed insights and metrics for @leanjs/react-router
Gathering detailed insights and metrics for @leanjs/react-router
npm install @leanjs/react-router
Typescript
Module System
Node Version
NPM Version
@leanjs/vue-router@0.7.8
Updated on Dec 31, 2022
@leanjs/webpack@0.21.8
Updated on Dec 18, 2022
@leanjs/webpack-vue@0.4.2
Updated on Dec 18, 2022
@leanjs/website@0.1.3
Updated on Dec 18, 2022
@leanjs/cli@0.7.38
Updated on Dec 18, 2022
@leanjs/next@0.8.12
Updated on Dec 18, 2022
TypeScript (79.84%)
JavaScript (14.19%)
Vue (2.14%)
Perl (1.62%)
Raku (1.33%)
CSS (0.52%)
HTML (0.33%)
Shell (0.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
170 Stars
949 Commits
6 Forks
4 Watchers
14 Branches
9 Contributors
Updated on May 28, 2025
Latest Version
0.13.11
Package Id
@leanjs/react-router@0.13.11
Unpacked Size
28.42 kB
Size
7.15 kB
File Count
23
NPM Version
lerna/5.6.2/node@v16.19.0+x64 (linux)
Node Version
16.19.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
If your React Router app is in a monorepo (recommended) execute the following command at the root of your repository:
1yarn add -W react-router-dom history react-dom react \ 2 @leanjs/react-router @leanjs/core @leanjs/react
then in the package.json
of your React Router app add the following peerDependencies
:
"peerDependencies": {
"@leanjs/core": "*",
"@leanjs/react-router": "*",
"@leanjs/react": "*",
"history": "*",
"react-router-dom": "*",
"react-dom": "*",
"react": "*"
}
If your React Router app is not in a monorepo, then run the following command instead of the above:
1yarn add react-router-dom history react-dom react \ 2 @leanjs/react-router @leanjs/core @leanjs/react
HostProvider
You have to add a HostProvider
at the root of the component tree of your React Router host app if you want to host composable apps within a React Router host. Heads up! HostProvider
is not exported from @leanjs/react-router
. Learn more about the HostProvider
.
Example:
1import React from "react"; 2import { BrowserRouter, Route, Routes } from "react-router-dom"; 3// for either React 16 or React 17 import from "@leanjs/react-router/17" 4import { Host } from "@leanjs/react-router/18"; 5// React runtime package created within your org 6import { HostProvider, createRuntime } from "@my-org/react-runtime"; 7 8import ExampleApp from "@my-org/example-app"; 9 10const runtime = createRuntime({ context: { appName: "AppExample" } }); 11 12const Root = () => ( 13 <HostProvider runtime={runtime}> 14 <BrowserRouter> 15 <Routes> 16 <Route path="/" element={<Host app={ExampleApp} />} /> 17 </Routes> 18 </BrowserRouter> 19 </HostProvider> 20); 21 22export default Root;
:::info
Read @leanjs/core if you have not already created your own createRuntime
function.
:::
Create small React Router apps that can be composed with other apps.
createApp
Arguments:
App: ReactElement
- requiredoptions: { appName?: string }
- optional. By default, the name of your composable app is the name of your App
component. You can change it using the optional argument appName
.Create a file called index.ts|js
in the src
directory where your composable app is. For example:
my-monorepo/
├─ apps/
│ ├─ react-router-host/
├─ composable-apps/
│ ├─ react-router-app-1/
│ │ ├─ package.json
│ │ ├─ src/
│ │ │ ├─ ReactRouterApp1.tsx
│ │ │ ├─ index.ts 👈
├─ package.json
:::tip
Read the recommended setup in our getting started page if you want to create a similar monorepo structure
:::
Call createApp
with the root component of your app, for example:
1// my-monorepo/composable-apps/react-router-app-1/src/index.ts 2 3// for either React 16 or React 17 import from "@leanjs/react-router/17" 4import { createApp } from "@leanjs/react-router/18"; 5 6import { ReactRouterApp1 } from "./ReactRouterApp1"; 7 8// 👇 you have to `export default` 9export default createApp(ReactRouterApp1); 10 11// The name of the composable app is the name of your component, 12// "ReactRouterApp1 in this case. 13// you can name it differently using the second argument, e.g. 14// export default createApp(ReactRouterApp1, { appName: "SomeName" });
Hello world example of the ReactRouterApp1
imported above
1// my-monorepo/composable-apps/react-router-app-1/src/ReactRouterApp1.tsx 2 3import React from "react"; 4 5export const ReactRouterApp1 = () => <h1>Hello React Router app</h1>;
Create a file called selfHosted.ts|js
in the src
directory where your composable app is, for example:
my-monorepo/
├─ apps/
│ ├─ react-router-host/
├─ composable-apps/
│ ├─ react-router-app-1/
│ │ ├─ package.json
│ │ ├─ src/
│ │ │ ├─ ReactRouterApp1.tsx
│ │ │ ├─ index.ts
│ │ │ ├─ selfHosted.ts 👈
├─ package.json
Export a createRuntime
function from the selfHosted.ts|js
file. This is the runtime that will be used when the app runs in isolation, meaning without a host.
1// my-monorepo/composable-apps/react-router-app-1/src/selfHosted.ts 2 3export { createRuntime } from "@my-org/runtime-react";
:::info
Read @leanjs/core if you have not already created your own createRuntime
function
:::
Host
It hosts a composable app in a React Router host.
app
- required propThe app
prop expects a GetComposableApp
type. You can import
a GetComposableApp
from any export default createApp()
function, for instance:
1// my-monorepo/composable -apps/react-router-app-1/src/ReactRouterApp1.tsx 2 3// for either React 16 or React 17 import from "@leanjs/react-router/17" 4import { createApp } from "@leanjs/react-router/18"; 5 6import { ReactRouterApp1 } from "./ReactRouterApp1"; 7 8export default createApp(ReactRouterApp1);
:::info
In this example, both the host app and the composable app are React Router apps. However, the React Router <Host>
component can host any composable app, e.g. Vue.
:::
then pass it to the Host
component in a React Router app:
1// my-monorepo/apps/react-router-host/src/pages/index.tsx 2 3// for either React 16 or React 17 import from "@leanjs/react-router/17" 4import { Host } from "@leanjs/react-router/18"; 5 6// this composable app is bundled and deployed along with the host app 7import ReactRouterApp1 from "@my-org/react-router-app-1"; 8 9const Home = () => ( 10 <> 11 <h1>React Router Host</h1> 12 <Host app={ReactRouterApp1} /> 13 </> 14); 15 16export default Home;
You can also pass a function to the Host
component that returns a dynamic import to lazy load a composable app:
1// my-monorepo/apps/react-router-host/src/pages/index.tsx 2 3import React, { Suspense } from "react"; 4// for either React 16 or React 17 import from "@leanjs/react-router/17" 5import { Host } from "@leanjs/react-router/18"; 6// for either React 16 or React 17 import from "@leanjs/react/17" 7import { ErrorBoundary } from "@leanjs/react/18"; 8 9const Home = () => ( 10 <> 11 <h1>React Router Host</h1> 12 {/* The network can fail. 13 Add an ErrorBoundary if you are hosting an app using a dynamic import */} 14 <ErrorBoundary> 15 <Suspense fallback={<p>Loading...</p>}> 16 <Host 17 app={() => { 18 // this composable app is bundled in a separate chunk 19 // but it's still built and deployed along with the host app 20 return import("@my-org/react-router-app-1"); 21 }} 22 /> 23 </Suspense> 24 </ErrorBoundary> 25 </> 26); 27 28export default Home;
Alternatively, you can pass an object to the app
prop with a packageName
key which value is the field name
in the package.json of the composable app that you want to host. In this case, the Host
component will try to fetch the mount
function from the remote origin
specified in <HostProvider origin=" 👉 HERE 👈 " runtime={runtime}>
(see origin prop to know more). For example:
1// my-monorepo/apps/react-router-host/src/pages/index.tsx 2 3import React, { Suspense } from "react"; 4// for either React 16 or React 17 import from "@leanjs/react-router/17" 5import { Host } from "@leanjs/react-router/18"; 6// for either React 16 or React 17 import from "@leanjs/react/17" 7import { ErrorBoundary } from "@leanjs/react/18"; 8 9const Home = () => ( 10 <> 11 <h1>React Host</h1> 12 {/* The network can fail. 13 Add an ErrorBoundary if you are hosting a remote app */} 14 <ErrorBoundary> 15 <Suspense fallback={<p>Loading...</p>}> 16 {/* in this case, the composable app is neither built nor deployed 17 along with the React host */} 18 <Host app={{ packageName: "@my-org/react-router-app-1" }} /> 19 </Suspense> 20 </ErrorBoundary> 21 </> 22); 23 24export default Home;
:::caution
Fetching from a remote origin
only works with Webpack v5 because this feature uses Module Federation under the hood. You need to add a HostWebpackPlugin to your Webpack configuration to enable this feature. If this feature is enabled you need to build and deploy your composable apps independently. See @leanjs/aws to deploy your composable apps to AWS.
:::
:::tip
You can still pass an import
(either dynamic or static) to the app
prop of the Host
component and configure Webpack to fetch it from a remote origin by changing the configuration of your HostWebpackPlugin
.
:::
Tip example:
1// webpack.config.js of the host application 2const { HostWebpackPlugin } = require("@leanjs/webpack"); 3 4module.exports = { 5 // the rest of your configuration goes here 6 plugins: [ 7 new HostWebpackPlugin({ 8 remotes: { 9 // these packages are not built along with the host app 10 // but downloaded from a remote origin 11 packages: ["@my-org/react-router-app-1"], 12 }, 13 }), 14 ], 15};
then in your React app:
1// @my-org/my-react-app pages/index.tsx 2 3import React, { Suspense } from "react"; 4// for either React 16 or React 17 import from "@leanjs/react-router/17" 5import { Host } from "@leanjs/react-router/18"; 6// for either React 16 or React 17 import from "@leanjs/react/17" 7import { ErrorBoundary } from "@leanjs/react/18"; 8 9// this composable app is neither bundled nor deployed along with the host app 10// because of the above remote: { packages: ["@my-org/react-router-app-1"] } 11// in the webpack.config.js HostWebpackPlugin 12import ReactRouterApp1 from "@my-org/react-router-app-1"; 13 14const Home = () => ( 15 <> 16 <h1>React Host</h1> 17 {/* The network can fail. 18 Add an ErrorBoundary if you are hosting a remote app */} 19 <ErrorBoundary> 20 <Suspense fallback={<p>Loading...</p>}> 21 <Host app={ReactRouterApp1} /> 22 </Suspense> 23 </ErrorBoundary> 24 </> 25); 26 27export default Home;
Pro-tip
Configure your remotes
in HostWebpackPlugin
on development only. This way no CI/CD changes are required. It also reduces build time of your monolith in development since these packages are excluded from the monolith build. Last but not least, you can experiment with micro-frontends in development without changing how you implement and host your apps.
Pro-tip example:
1// webpack.config.js of the host application 2const { HostWebpackPlugin } = require("@leanjs/webpack"); 3 4module.exports = { 5 // the rest of your configuration goes here 6 plugins: [ 7 new HostWebpackPlugin({ 8 remotes: { 9 // the following packages are built and deployed along with 10 // the React Router app on production, but not during development. 11 packages: 12 process.env.NODE_ENV === "production" 13 ? [] 14 : ["@my-org/react-router-app-1"], 15 }, 16 }), 17 ], 18};
className
- optional propCSS class added to the root DOM element where the app
prop is mounted.
1// my-monorepo/apps/react-host/src/index.ts 2 3import React from "react"; 4// for either React 16 or React 17 import from "@leanjs/react-router/17" 5import { Host } from "@leanjs/react-router/18"; 6import ReactRouterApp1 from "@my-org/react-router-app-1"; 7 8const Home = () => ( 9 <> 10 <h1>React Host</h1> 11 <Host className="some-css-class" app={ReactRouterApp1} /> 12 </> 13); 14 15export default Home;
basename
- optional propIt makes all routes and links in your app relative to a "base" portion of the URL pathname that they all share. For instance, you could render an app BestSellingBooksApp
in the following URL https://fake-bookstore.com/best-sellers
.
BestSellingBooksApp
doesn't need to define internally the segment in the URL pathname where it is hosted. In this example basename
is /best-sellers
, and it could be changed, e.g. https://fake-bookstore.com/top-📚
, without having to change anything inside BestSellingBooksApp
. The "base" portion of the URL pathname where BestSellingBooksApp
is hosted is responsibility of the host.
1// my-monorepo/apps/react-host/src/index.ts 2 3import React from "react"; 4// for either React 16 or React 17 import from "@leanjs/react-router/17" 5import { Host } from "@leanjs/react-router/18"; 6import BestSellingBooksApp from "@my-org/best-selling-books"; 7 8const Home = () => ( 9 <> 10 <h1>React Host</h1> 11 <Host basename="/best-sellers" app={BestSellingBooksApp} /> 12 </> 13); 14 15export default Home;
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/6 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
87 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More