New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-router-dom-v5-compat

Package Overview
Dependencies
Maintainers
1
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-dom-v5-compat - npm Package Compare versions

Comparing version 6.2.2 to 6.3.0

2

index.d.ts

@@ -52,2 +52,2 @@ /**

export type { StaticRouterProps } from "./lib/components";
export { CompatRouter, StaticRouter } from "./lib/components";
export { CompatRouter, CompatRoute, StaticRouter } from "./lib/components";
/**
* React Router DOM v5 Compat v6.2.2
* React Router DOM v5 Compat v6.3.0
*

@@ -11,7 +11,7 @@ * Copyright (c) Remix Software Inc.

*/
import { useRef, useState, useLayoutEffect, createElement, forwardRef, useCallback, useMemo, useEffect } from 'react';
import { useRef, useState, useLayoutEffect, createElement, forwardRef, useCallback, useMemo } from 'react';
import { createBrowserHistory, createHashHistory, parsePath, Action, createPath as createPath$1 } from 'history';
import { Router, useHref, createPath, useLocation, useResolvedPath, useNavigate, Routes, Route } from 'react-router';
export { MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes } from 'react-router';
import { useHistory } from 'react-router-dom';
import { Route as Route$1, useHistory } from 'react-router-dom';

@@ -371,2 +371,14 @@ function _extends() {

// but not worried about that for now.
function CompatRoute(props) {
let {
path
} = props;
if (!props.exact) path += "/*";
return /*#__PURE__*/createElement(Routes, null, /*#__PURE__*/createElement(Route, {
path: path,
element: /*#__PURE__*/createElement(Route$1, props)
}));
}
function CompatRouter(_ref) {

@@ -381,3 +393,3 @@ let {

}));
useEffect(() => {
useLayoutEffect(() => {
history.listen((location, action) => setState({

@@ -457,3 +469,3 @@ location,

export { BrowserRouter, CompatRouter, HashRouter, Link, NavLink, StaticRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, useLinkClickHandler, useSearchParams };
export { BrowserRouter, CompatRoute, CompatRouter, HashRouter, Link, NavLink, StaticRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, useLinkClickHandler, useSearchParams };
//# sourceMappingURL=index.js.map
import * as React from "react";
import type { Location } from "history";
export declare function CompatRoute(props: any): JSX.Element;
export declare function CompatRouter({ children }: {

@@ -4,0 +5,0 @@ children: React.ReactNode;

/**
* React Router DOM v5 Compat v6.2.2
* React Router DOM v5 Compat v6.3.0
*

@@ -4,0 +4,0 @@ * Copyright (c) Remix Software Inc.

{
"name": "react-router-dom-v5-compat",
"version": "6.2.2",
"version": "6.3.0",
"author": "Remix Software <hello@remix.run>",

@@ -16,2 +16,6 @@ "description": "Migration path to React Router v6 from v4/5",

"unpkg": "./umd/react-router.production.min.js",
"dependencies": {
"history": "^5.3.0",
"react-router": "6.3.0"
},
"peerDependencies": {

@@ -22,6 +26,2 @@ "react": ">=16.8",

},
"dependencies": {
"history": "^5.3.0",
"react-router": "6.2.2"
},
"sideEffects": false,

@@ -28,0 +28,0 @@ "keywords": [

@@ -60,3 +60,3 @@ /**

export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
children: React.ReactNode | ((props: {
children?: React.ReactNode | ((props: {
isActive: boolean;

@@ -63,0 +63,0 @@ }) => React.ReactNode);

# React Router DOM Compat v5
TODO
This package enables React Router web apps to incrementally migrate to the latest API in v6 by running it in parallel with v5. It is a copy of v6 with an extra couple of components to keep the two in sync.
## Incremental Migration
Instead of upgrading and updating all of your code at once (which is incredibly difficult and prone to bugs), this strategy enables you to upgrade one component, one hook, and one route at a time by running both v5 and v6 in parallel. Any code you haven't touched is still running the very same code it was before. Once all components are exclusively using the v6 APIs, your app no longer needs the compatibility package and is running on v6.
It looks something like this:
- Setup the `CompatRouter`
- Change a `<Route>` inside of a `<Switch>` to a `<CompatRoute>`
- Update all APIs inside this route element tree to v6 APIs one at a time
- Repeat for all routes in the `<Switch>`
- Convert the `<Switch>` to a `<Routes>`
- Repeat for all ancestor `<Switch>`s
- Update `<Links>`
- You're done!
## Setting up
These are the most common cases, be sure to read the v6 docs to figure out how to do anything not shown here.
Please [open a discussion on GitHub][discussion] if you're stuck, we'll be happy to help. We would also love for this GitHub Q&A to fill up with migration tips for the entire community, so feel free to add your tips even when you're not stuck!
### 1) Upgrade your app to React 16.8+
React Router v6 has been rewritten with React Hooks, significantly improving bundle sizes and composition. You will need to upgrade to 16.8+ in order to migrate to React Router v6.
You can read the [Hooks Adoption Strategy](https://reactjs.org/docs/hooks-faq.html#adoption-strategy) from the React docs for help there.
### 2) Install Compatibility Package
👉 Install the package
```sh
npm install react-router-dom-v5-compat
```
This package includes the v6 API so that you can run it in parallel with v5.
### 3) Render the Compatibility Router
The compatibility package includes a special `CompatRouter` that synchronizes the v5 and v6 APIs state so that both APIs are available.
👉 Render the `<CompatRouter>` directly below your v5 `<BrowserRouter>`.
```diff
import { BrowserRouter } from "react-router-dom";
+import { CompatRouter } from "react-router-dom-v5-compat";
export function App() {
return (
<BrowserRouter>
+ <CompatRouter>
<Switch>
<Route path="/" exact component={Home} />
{/* ... */}
</Switch>
+ </CompatRouter>
</BrowserRouter>
);
}
```
For the curious, this component accesses the `history` from v5, sets up a listener, and then renders a "controlled" v6 `<Router>`. This way both v5 and v6 APIs are talking to the same `history` instance.
### 4) Commit and Ship!
The whole point of this package is to allow you to incrementally migrate your code instead of a giant, risky upgrade that often halts any other feature work.
👉 Commit the changes and ship!
```sh
git add .
git commit -m 'setup router compatibility package'
# of course this may be different for you
git push origin main
```
It's not much yet, but now you're ready.
## Migration Strategy
The migration is easiest if you start from the bottom of your component tree and climb up each branch to the top.
You can start at the top, too, but then you can't migrate an entire branch of your UI to v6 completely which makes it tempting to keep using v5 APIs when working in any part of your app: "two steps forward, one step back". By migrating an entire Route's element tree to v6, new feature work there is less likely to pull in the v5 APIs.
### 1) Render CompatRoute elements inside of Switch
👉 Change `<Route>` to `<CompatRoute>`
```diff
import { Route } from "react-router-dom";
+ import { CompatRoute } from "react-router-dom-v5-compat";
export function SomComp() {
return (
<Switch>
- <Route path="/project/:id" component={Project} />
+ <CompatRoute path="/project/:id" component={Project} />
</Switch>
)
}
```
`<CompatRoute>` renders a v5 `<Route>` wrapped inside of a v6 context. This is the special sauce that makes both APIs available to the component tree inside of this route.
⚠️️ You can only use `CompatRoute` inside of a `Switch`, it will not work for Routes that are rendered outside of `<Switch>`. Depending on the use case, there will be a hook in v6 to meet it.
⚠️ You can't use regular expressions or optional params in v6 route paths. Instead, repeat the route with the extra params/regex patterns you're trying to match.
```diff
- <Route path="/one/:two?" element={Comp} />
+ <CompatRoute path="/one/:two" element={Comp} />
+ <CompatRoute path="/one" element={Comp} />
```
### 2) Change component code use v6 instead of v5 APIs
This route now has both v5 and v6 routing contexts, so we can start migrating component code to v6.
If the component is a class component, you'll need to convert it to a function component first so that you can use hooks.
👉 Read from v6 `useParams()` instead of v5 `props.match`
```diff
+ import { useParams } from "react-router-dom-v5-compat";
function Project(props) {
- const { params } = props.match;
+ const params = useParams();
// ...
}
```
👉 Commit and ship!
```sh
git add .
git commit -m "chore: RR v5 props.match -> v6 useParams"
git push origin main
```
This component is now using both APIs at the same time. Every small change can be committed and shipped. No need for a long running branch that makes you want to quit your job, build a cabin in the woods, and live off of squirrels and papago lilies.
👉 Read from v6 `useLocation()` instead of v5 `props.location`
```diff
+ import { useLocation } from "react-router-dom-v5-compat";
function Project(props) {
- const location = props.location;
+ const location = useLocation();
// ...
}
```
👉 Use `navigate` instead of `history`
```diff
+ import { useNavigate } from "react-router-dom-v5-compat";
function Project(props) {
- const history = props.history;
+ const navigate = useNavigate();
return (
<div>
<MenuList>
<MenuItem onClick={() => {
- history.push("/elsewhere");
+ navigate("/elsewhere");
- history.replace("/elsewhere");
+ navigate("/elsewhere", { replace: true });
- history.go(-1);
+ navigate(-1);
}} />
</MenuList>
</div>
)
}
```
There are more APIs you may be accessing, but these are the most common. Again, [open a discussion on GitHub][discussion] if you're stuck and we'll do our best to help out.
### 3) (Maybe) Update Links and NavLinks
Some links may be building on `match.url` to link to deeper URLs without needing to know the portion of the URL before them. You no longer need to build the path manually, React Router v6 supports relative links.
👉 Update links to use relative `to` values
```diff
- import { Link } from "react-router-dom";
+ import { Link } from "react-router-dom-v5-compat";
function Project(props) {
return (
<div>
- <Link to={`${props.match.url}/edit`} />
+ <Link to="edit" />
</div>
)
}
```
The way to define active className and style props has been simplified to a callback to avoid specificity issues with CSS:
👉 Update nav links
```diff
- import { NavLink } from "react-router-dom";
+ import { NavLink } from "react-router-dom-v5-compat";
function Project(props) {
return (
<div>
- <NavLink exact to="/dashboard" />
+ <NavLink end to="/dashboard" />
- <NavLink activeClassName="blue" className="red" />
+ <NavLink className={({ isActive }) => isActive ? "blue" : "red" } />
- <NavLink activeStyle={{ color: "blue" }} style={{ color: "red" }} />
+ <NavLink style={({ isActive }) => ({ color: isActive ? "blue" : "red" }) />
</div>
)
}
```
### 4) Convert `Switch` to `Routes`
Once every descendant component in a `<Switch>` has been migrated to v6, you can convert the `<Switch>` to `<Routes>` and change the `<CompatRoute>` elements to v6 `<Route>` elements.
👉 Convert `<Switch>` to `<Routes>` and `<CompatRoute>` to v6 `<Route>`
```diff
import { Routes, Route } from "react-router-dom-v5-compat";
- import { Switch, Route } from "react-router-dom"
- <Switch>
- <CompatRoute path="/" exact component={Home} />
- <CompatRoute path="/projects/:projectId" component={Project} />
- </Switch>
+ <Routes>
+ <Route path="/" element={<Home />} />
+ <Route path="projects/:projectId" element={<Project />} />
+ </Routes>
```
BAM 💥 This entire branch of your UI is migrated to v6!
### 5) Rinse and Repeat up the tree
Once your deepest `Switch` components are converted, go up to their parent `<Switch>` and repeat the process. Keep doing this all the way up the tree until all components are migrated to v6 APIs.
When you convert a `<Switch>` to `<Routes>` that has descendant `<Routes>` deeper in its tree, there are a couple things you need to do in both places for everything to continue matching correctly.
👉️ Add splat paths to any `<Route>` with a **descendant** `<Routes>`
```diff
function Root() {
return (
<Routes>
- <Route path="/projects" element={<Projects />} />
+ <Route path="/projects/*" element={<Projects />} />
</Routes>
);
}
```
This ensures deeper URLs like `/projects/123` continue to match that route. Note that this isn't needed if the route doesn't have any descendant `<Routes>`.
👉 Convert route paths from absolute to relative paths
```diff
- function Projects(props) {
- let { match } = props
function Projects() {
return (
<div>
<h1>Projects</h1>
<Routes>
- <Route path={match.path + "/activity"} element={<ProjectsActivity />} />
- <Route path={match.path + "/:projectId"} element={<Project />} />
- <Route path={match.path + "/:projectId/edit"} element={<EditProject />} />
+ <Route path="activity" element={<ProjectsActivity />} />
+ <Route path=":projectId" element={<Project />} />
+ <Route path=":projectId/edit" element={<EditProject />} />
</Routes>
</div>
);
}
```
Usually descendant Switch (and now Routes) were using the ancestor `match.path` to build their entire path. When the ancestor Switch is converted to `<Routes>` you no longer need to do this this manually, it happens automatically. Also, if you don't change them to relative paths, they will no longer match, so you need to do this step.
### 6) Remove the compatibility package!
Once you've converted all of your code you can remove the compatibility package and install React Router DOM v6 directly. We have to do a few things all at once to finish this off.
👉 Remove the compatibility package
```sh
npm uninstall react-router-dom-v5-compat
```
👉 Uninstall `react-router` and `history`
v6 no longer requires history or react-router to be peer dependencies (they're normal dependencies now), so you'll need to uninstall them
```
npm uninstall react-router history
```
👉 Install React Router v6
```sh
npm install react-router-dom@6
```
👉 Remove the `CompatRouter`
```diff
import { BrowserRouter } from "react-router-dom";
- import { CompatRouter } from "react-router-dom-v5-compat";
export function App() {
return (
<BrowserRouter>
- <CompatRouter>
<Routes>
<Route path="/" element={<Home />} />
{/* ... */}
</Routes>
- </CompatRouter>
</BrowserRouter>
);
}
```
Note that `BrowserRouter` is now the v6 browser router.
👉 Change all compat imports to "react-router-dom"
You should be able to a find/replace across the project to change all instances of "react-router-dom-v5-compat" to "react-router-dom"
```sh
# Change `src` to wherever your source modules live
# Also strap on a fake neckbeard cause it's shell scripting time
git grep -lz src | xargs -0 sed -i '' -e 's/react-router-dom-v5-compat/react-router-dom/g'
```
### 7) Optional: lift `Routes` up to single route config
This part is optional (but you'll want it when the React Router data APIs ship).
Once you've converted all of your app to v6, you can lift every `<Routes>` to the top of the app and replace it with an `<Outlet>`. React Router v6 has a concept of "nested routes".
👉 Replace descendant `<Routes>` with `<Outlet/>`
```diff
- <Routes>
- <Route path="one" />
- <Route path="two" />
- </Routes>
+ <Outlet />
```
👉 Lift the `<Route>` elements to the ancestor `<Routes>`
```diff
<Routes>
<Route path="three" />
<Route path="four" />
+ <Route path="one" />
+ <Route path="two" />
</Routes>
```
If you had splat paths for descendant routes, you can remove them when the descendant routes lift up to the same route configuration:
```diff
<Routes>
- <Route path="projects/*">
+ <Route path="projects">
<Route path="activity" element={<ProjectsActivity />} />
<Route path=":projectId" element={<Project />} />
<Route path=":projectId/edit" element={<EditProject />} />
</Route>
</Routes>
```
That's it, you're done 🙌
Don't forget to [open a discussion on GitHub][discussion] if you're stuck, add your own tips, and help others with their questions 🙏
[discussion]: https://github.com/remix-run/react-router/discussions/new?category=v5-to-v6-migration
/**
* React Router DOM v5 Compat v6.2.2
* React Router DOM v5 Compat v6.3.0
*

@@ -370,2 +370,14 @@ * Copyright (c) Remix Software Inc.

// but not worried about that for now.
function CompatRoute(props) {
let {
path
} = props;
if (!props.exact) path += "/*";
return /*#__PURE__*/React.createElement(reactRouter.Routes, null, /*#__PURE__*/React.createElement(reactRouter.Route, {
path: path,
element: /*#__PURE__*/React.createElement(reactRouterDom.Route, props)
}));
}
function CompatRouter(_ref) {

@@ -380,3 +392,3 @@ let {

}));
React.useEffect(() => {
React.useLayoutEffect(() => {
history.listen((location, action) => setState({

@@ -631,2 +643,3 @@ location,

exports.BrowserRouter = BrowserRouter;
exports.CompatRoute = CompatRoute;
exports.CompatRouter = CompatRouter;

@@ -633,0 +646,0 @@ exports.HashRouter = HashRouter;

/**
* React Router DOM v5 Compat v6.2.2
* React Router DOM v5 Compat v6.3.0
*

@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc.

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("history"),require("react-router"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","history","react-router","react-router-dom"],t):t((e=e||self).ReactRouterDOMv5Compat={},e.React,e.HistoryLibrary,e.ReactRouter,e.ReactRouterDOM)}(this,(function(e,t,r,n,a){"use strict";function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}const i=["onClick","reloadDocument","replace","state","target","to"],c=["aria-current","caseSensitive","className","end","style","to","children"];const s=t.forwardRef((function(e,r){let{onClick:a,reloadDocument:c,replace:s=!1,state:l,target:h,to:y}=e,p=u(e,i),b=n.useHref(y),d=f(y,{replace:s,state:l,target:h});return t.createElement("a",o({},p,{href:b,onClick:function(e){a&&a(e),e.defaultPrevented||c||d(e)},ref:r,target:h}))})),l=t.forwardRef((function(e,r){let{"aria-current":a="page",caseSensitive:i=!1,className:l="",end:f=!1,style:h,to:y,children:p}=e,b=u(e,c),d=n.useLocation(),m=n.useResolvedPath(y),g=d.pathname,v=m.pathname;i||(g=g.toLowerCase(),v=v.toLowerCase());let P,R=g===v||!f&&g.startsWith(v)&&"/"===g.charAt(v.length),O=R?a:void 0;P="function"==typeof l?l({isActive:R}):[l,R?"active":null].filter(Boolean).join(" ");let w="function"==typeof h?h({isActive:R}):h;return t.createElement(s,o({},b,{"aria-current":O,className:P,ref:r,style:w,to:y}),"function"==typeof p?p({isActive:R}):p)}));function f(e,r){let{target:a,replace:o,state:u}=void 0===r?{}:r,i=n.useNavigate(),c=n.useLocation(),s=n.useResolvedPath(e);return t.useCallback((t=>{if(!(0!==t.button||a&&"_self"!==a||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(t))){t.preventDefault();let r=!!o||n.createPath(c)===n.createPath(s);i(e,{replace:r,state:u})}}),[c,i,s,o,u,a,e])}function h(e){return void 0===e&&(e=""),new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}Object.defineProperty(e,"MemoryRouter",{enumerable:!0,get:function(){return n.MemoryRouter}}),Object.defineProperty(e,"Navigate",{enumerable:!0,get:function(){return n.Navigate}}),Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return n.NavigationType}}),Object.defineProperty(e,"Outlet",{enumerable:!0,get:function(){return n.Outlet}}),Object.defineProperty(e,"Route",{enumerable:!0,get:function(){return n.Route}}),Object.defineProperty(e,"Router",{enumerable:!0,get:function(){return n.Router}}),Object.defineProperty(e,"Routes",{enumerable:!0,get:function(){return n.Routes}}),Object.defineProperty(e,"UNSAFE_LocationContext",{enumerable:!0,get:function(){return n.UNSAFE_LocationContext}}),Object.defineProperty(e,"UNSAFE_NavigationContext",{enumerable:!0,get:function(){return n.UNSAFE_NavigationContext}}),Object.defineProperty(e,"UNSAFE_RouteContext",{enumerable:!0,get:function(){return n.UNSAFE_RouteContext}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return n.createPath}}),Object.defineProperty(e,"createRoutesFromChildren",{enumerable:!0,get:function(){return n.createRoutesFromChildren}}),Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return n.generatePath}}),Object.defineProperty(e,"matchPath",{enumerable:!0,get:function(){return n.matchPath}}),Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return n.matchRoutes}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return n.parsePath}}),Object.defineProperty(e,"renderMatches",{enumerable:!0,get:function(){return n.renderMatches}}),Object.defineProperty(e,"resolvePath",{enumerable:!0,get:function(){return n.resolvePath}}),Object.defineProperty(e,"useHref",{enumerable:!0,get:function(){return n.useHref}}),Object.defineProperty(e,"useInRouterContext",{enumerable:!0,get:function(){return n.useInRouterContext}}),Object.defineProperty(e,"useLocation",{enumerable:!0,get:function(){return n.useLocation}}),Object.defineProperty(e,"useMatch",{enumerable:!0,get:function(){return n.useMatch}}),Object.defineProperty(e,"useNavigate",{enumerable:!0,get:function(){return n.useNavigate}}),Object.defineProperty(e,"useNavigationType",{enumerable:!0,get:function(){return n.useNavigationType}}),Object.defineProperty(e,"useOutlet",{enumerable:!0,get:function(){return n.useOutlet}}),Object.defineProperty(e,"useOutletContext",{enumerable:!0,get:function(){return n.useOutletContext}}),Object.defineProperty(e,"useParams",{enumerable:!0,get:function(){return n.useParams}}),Object.defineProperty(e,"useResolvedPath",{enumerable:!0,get:function(){return n.useResolvedPath}}),Object.defineProperty(e,"useRoutes",{enumerable:!0,get:function(){return n.useRoutes}}),e.BrowserRouter=function(e){let{basename:a,children:o,window:u}=e,i=t.useRef();null==i.current&&(i.current=r.createBrowserHistory({window:u}));let c=i.current,[s,l]=t.useState({action:c.action,location:c.location});return t.useLayoutEffect((()=>c.listen(l)),[c]),t.createElement(n.Router,{basename:a,children:o,location:s.location,navigationType:s.action,navigator:c})},e.CompatRouter=function(e){let{children:r}=e,o=a.useHistory(),[u,i]=t.useState((()=>({location:o.location,action:o.action})));return t.useEffect((()=>{o.listen(((e,t)=>i({location:e,action:t})))}),[o]),t.createElement(n.Router,{navigationType:u.action,location:u.location,navigator:o},t.createElement(n.Routes,null,t.createElement(n.Route,{path:"*",element:r})))},e.HashRouter=function(e){let{basename:a,children:o,window:u}=e,i=t.useRef();null==i.current&&(i.current=r.createHashHistory({window:u}));let c=i.current,[s,l]=t.useState({action:c.action,location:c.location});return t.useLayoutEffect((()=>c.listen(l)),[c]),t.createElement(n.Router,{basename:a,children:o,location:s.location,navigationType:s.action,navigator:c})},e.Link=s,e.NavLink=l,e.StaticRouter=function(e){let{basename:a,children:o,location:u="/"}=e;"string"==typeof u&&(u=r.parsePath(u));let i=r.Action.Pop,c={pathname:u.pathname||"/",search:u.search||"",hash:u.hash||"",state:u.state||null,key:u.key||"default"},s={createHref:e=>"string"==typeof e?e:r.createPath(e),push(e){throw new Error("You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+JSON.stringify(e)+")` somewhere in your app.")},replace(e){throw new Error("You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+JSON.stringify(e)+", { replace: true })` somewhere in your app.")},go(e){throw new Error("You cannot use navigator.go() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+e+")` somewhere in your app.")},back(){throw new Error("You cannot use navigator.back() on the server because it is a stateless environment.")},forward(){throw new Error("You cannot use navigator.forward() on the server because it is a stateless environment.")}};return t.createElement(n.Router,{basename:a,children:o,location:c,navigationType:i,navigator:s,static:!0})},e.createSearchParams=h,e.unstable_HistoryRouter=function(e){let{basename:r,children:a,history:o}=e;const[u,i]=t.useState({action:o.action,location:o.location});return t.useLayoutEffect((()=>o.listen(i)),[o]),t.createElement(n.Router,{basename:r,children:a,location:u.location,navigationType:u.action,navigator:o})},e.useLinkClickHandler=f,e.useSearchParams=function(e){let r=t.useRef(h(e)),a=n.useLocation(),o=t.useMemo((()=>{let e=h(a.search);for(let t of r.current.keys())e.has(t)||r.current.getAll(t).forEach((r=>{e.append(t,r)}));return e}),[a.search]),u=n.useNavigate();return[o,t.useCallback(((e,t)=>{u("?"+h(e),t)}),[u])]},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("history"),require("react-router"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","history","react-router","react-router-dom"],t):t((e=e||self).ReactRouterDOMv5Compat={},e.React,e.HistoryLibrary,e.ReactRouter,e.ReactRouterDOM)}(this,(function(e,t,r,n,a){"use strict";function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}const i=["onClick","reloadDocument","replace","state","target","to"],c=["aria-current","caseSensitive","className","end","style","to","children"];const s=t.forwardRef((function(e,r){let{onClick:a,reloadDocument:c,replace:s=!1,state:l,target:h,to:p}=e,y=u(e,i),m=n.useHref(p),b=f(p,{replace:s,state:l,target:h});return t.createElement("a",o({},y,{href:m,onClick:function(e){a&&a(e),e.defaultPrevented||c||b(e)},ref:r,target:h}))})),l=t.forwardRef((function(e,r){let{"aria-current":a="page",caseSensitive:i=!1,className:l="",end:f=!1,style:h,to:p,children:y}=e,m=u(e,c),b=n.useLocation(),d=n.useResolvedPath(p),g=b.pathname,v=d.pathname;i||(g=g.toLowerCase(),v=v.toLowerCase());let P,R=g===v||!f&&g.startsWith(v)&&"/"===g.charAt(v.length),O=R?a:void 0;P="function"==typeof l?l({isActive:R}):[l,R?"active":null].filter(Boolean).join(" ");let w="function"==typeof h?h({isActive:R}):h;return t.createElement(s,o({},m,{"aria-current":O,className:P,ref:r,style:w,to:p}),"function"==typeof y?y({isActive:R}):y)}));function f(e,r){let{target:a,replace:o,state:u}=void 0===r?{}:r,i=n.useNavigate(),c=n.useLocation(),s=n.useResolvedPath(e);return t.useCallback((t=>{if(!(0!==t.button||a&&"_self"!==a||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(t))){t.preventDefault();let r=!!o||n.createPath(c)===n.createPath(s);i(e,{replace:r,state:u})}}),[c,i,s,o,u,a,e])}function h(e){return void 0===e&&(e=""),new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}Object.defineProperty(e,"MemoryRouter",{enumerable:!0,get:function(){return n.MemoryRouter}}),Object.defineProperty(e,"Navigate",{enumerable:!0,get:function(){return n.Navigate}}),Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return n.NavigationType}}),Object.defineProperty(e,"Outlet",{enumerable:!0,get:function(){return n.Outlet}}),Object.defineProperty(e,"Route",{enumerable:!0,get:function(){return n.Route}}),Object.defineProperty(e,"Router",{enumerable:!0,get:function(){return n.Router}}),Object.defineProperty(e,"Routes",{enumerable:!0,get:function(){return n.Routes}}),Object.defineProperty(e,"UNSAFE_LocationContext",{enumerable:!0,get:function(){return n.UNSAFE_LocationContext}}),Object.defineProperty(e,"UNSAFE_NavigationContext",{enumerable:!0,get:function(){return n.UNSAFE_NavigationContext}}),Object.defineProperty(e,"UNSAFE_RouteContext",{enumerable:!0,get:function(){return n.UNSAFE_RouteContext}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return n.createPath}}),Object.defineProperty(e,"createRoutesFromChildren",{enumerable:!0,get:function(){return n.createRoutesFromChildren}}),Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return n.generatePath}}),Object.defineProperty(e,"matchPath",{enumerable:!0,get:function(){return n.matchPath}}),Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return n.matchRoutes}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return n.parsePath}}),Object.defineProperty(e,"renderMatches",{enumerable:!0,get:function(){return n.renderMatches}}),Object.defineProperty(e,"resolvePath",{enumerable:!0,get:function(){return n.resolvePath}}),Object.defineProperty(e,"useHref",{enumerable:!0,get:function(){return n.useHref}}),Object.defineProperty(e,"useInRouterContext",{enumerable:!0,get:function(){return n.useInRouterContext}}),Object.defineProperty(e,"useLocation",{enumerable:!0,get:function(){return n.useLocation}}),Object.defineProperty(e,"useMatch",{enumerable:!0,get:function(){return n.useMatch}}),Object.defineProperty(e,"useNavigate",{enumerable:!0,get:function(){return n.useNavigate}}),Object.defineProperty(e,"useNavigationType",{enumerable:!0,get:function(){return n.useNavigationType}}),Object.defineProperty(e,"useOutlet",{enumerable:!0,get:function(){return n.useOutlet}}),Object.defineProperty(e,"useOutletContext",{enumerable:!0,get:function(){return n.useOutletContext}}),Object.defineProperty(e,"useParams",{enumerable:!0,get:function(){return n.useParams}}),Object.defineProperty(e,"useResolvedPath",{enumerable:!0,get:function(){return n.useResolvedPath}}),Object.defineProperty(e,"useRoutes",{enumerable:!0,get:function(){return n.useRoutes}}),e.BrowserRouter=function(e){let{basename:a,children:o,window:u}=e,i=t.useRef();null==i.current&&(i.current=r.createBrowserHistory({window:u}));let c=i.current,[s,l]=t.useState({action:c.action,location:c.location});return t.useLayoutEffect((()=>c.listen(l)),[c]),t.createElement(n.Router,{basename:a,children:o,location:s.location,navigationType:s.action,navigator:c})},e.CompatRoute=function(e){let{path:r}=e;return e.exact||(r+="/*"),t.createElement(n.Routes,null,t.createElement(n.Route,{path:r,element:t.createElement(a.Route,e)}))},e.CompatRouter=function(e){let{children:r}=e,o=a.useHistory(),[u,i]=t.useState((()=>({location:o.location,action:o.action})));return t.useLayoutEffect((()=>{o.listen(((e,t)=>i({location:e,action:t})))}),[o]),t.createElement(n.Router,{navigationType:u.action,location:u.location,navigator:o},t.createElement(n.Routes,null,t.createElement(n.Route,{path:"*",element:r})))},e.HashRouter=function(e){let{basename:a,children:o,window:u}=e,i=t.useRef();null==i.current&&(i.current=r.createHashHistory({window:u}));let c=i.current,[s,l]=t.useState({action:c.action,location:c.location});return t.useLayoutEffect((()=>c.listen(l)),[c]),t.createElement(n.Router,{basename:a,children:o,location:s.location,navigationType:s.action,navigator:c})},e.Link=s,e.NavLink=l,e.StaticRouter=function(e){let{basename:a,children:o,location:u="/"}=e;"string"==typeof u&&(u=r.parsePath(u));let i=r.Action.Pop,c={pathname:u.pathname||"/",search:u.search||"",hash:u.hash||"",state:u.state||null,key:u.key||"default"},s={createHref:e=>"string"==typeof e?e:r.createPath(e),push(e){throw new Error("You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+JSON.stringify(e)+")` somewhere in your app.")},replace(e){throw new Error("You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+JSON.stringify(e)+", { replace: true })` somewhere in your app.")},go(e){throw new Error("You cannot use navigator.go() on the server because it is a stateless environment. This error was probably triggered when you did a `navigate("+e+")` somewhere in your app.")},back(){throw new Error("You cannot use navigator.back() on the server because it is a stateless environment.")},forward(){throw new Error("You cannot use navigator.forward() on the server because it is a stateless environment.")}};return t.createElement(n.Router,{basename:a,children:o,location:c,navigationType:i,navigator:s,static:!0})},e.createSearchParams=h,e.unstable_HistoryRouter=function(e){let{basename:r,children:a,history:o}=e;const[u,i]=t.useState({action:o.action,location:o.location});return t.useLayoutEffect((()=>o.listen(i)),[o]),t.createElement(n.Router,{basename:r,children:a,location:u.location,navigationType:u.action,navigator:o})},e.useLinkClickHandler=f,e.useSearchParams=function(e){let r=t.useRef(h(e)),a=n.useLocation(),o=t.useMemo((()=>{let e=h(a.search);for(let t of r.current.keys())e.has(t)||r.current.getAll(t).forEach((r=>{e.append(t,r)}));return e}),[a.search]),u=n.useNavigate();return[o,t.useCallback(((e,t)=>{u("?"+h(e),t)}),[u])]},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=react-router-dom-v5-compat.production.min.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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