Socket
Socket
Sign inDemoInstall

react-router-dom

Package Overview
Dependencies
Maintainers
3
Versions
419
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-dom - npm Package Versions

1
ā€¦
ā€¦
42

6.10.0-pre.1

Diff

mjackson
published 6.10.0-pre.0 ā€¢

mjackson
published 0.0.0-experimental-42adf24c ā€¢

mjackson
published 0.0.0-experimental-cec61865 ā€¢

mjackson
published 0.0.0-experimental-0f2dd78c ā€¢

mjackson
published 0.0.0-experimental-b162e81d ā€¢

mjackson
published 0.0.0-experimental-00c655af ā€¢

mjackson
published 0.0.0-experimental-f3b593c3 ā€¢

mjackson
published 6.9.0 ā€¢

Changelog

Source

v6.9.0

Date: 2023-03-10

What's Changed

Component/ErrorBoundary route properties

React Router now supports an alternative way to define your route element and errorElement fields as React Components instead of React Elements. You can instead pass a React Component to the new Component and ErrorBoundary fields if you choose. There is no functional difference between the two, so use whichever approach you prefer šŸ˜€. You shouldn't be defining both, but if you do Component/ErrorBoundary will "win"

Example JSON Syntax

// Both of these work the same:
const elementRoutes = [{
  path: '/',
  element: <Home />,
  errorElement: <HomeError />,
}]

const componentRoutes = [{
  path: '/',
  Component: Home,
  ErrorBoundary: HomeError,
}]

function Home() { ... }
function HomeError() { ... }

Example JSX Syntax

// Both of these work the same:
const elementRoutes = createRoutesFromElements(
  <Route path='/' element={<Home />} errorElement={<HomeError /> } />
);

const componentRoutes = createRoutesFromElements(
  <Route path='/' Component={Home} ErrorBoundary={HomeError} />
);

function Home() { ... }
function HomeError() { ... }
Introducing Lazy Route Modules

In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new lazy() route property. This is an async function that resolves the non-route-matching portions of your route definition (loader, action, element/Component, errorElement/ErrorBoundary, shouldRevalidate, handle).

Lazy routes are resolved on initial load and during the loading or submitting phase of a navigation or fetcher call. You cannot lazily define route-matching properties (path, index, children) since we only execute your lazy route functions after we've matched known routes.

Your lazy functions will typically return the result of a dynamic import.

// In this example, we assume most folks land on the homepage so we include that
// in our critical-path bundle, but then we lazily load modules for /a and /b so
// they don't load until the user navigates to those routes
let routes = createRoutesFromElements(
  <Route path="/" element={<Layout />}>
    <Route index element={<Home />} />
    <Route path="a" lazy={() => import("./a")} />
    <Route path="b" lazy={() => import("./b")} />
  </Route>
);

Then in your lazy route modules, export the properties you want defined for the route:

export async function loader({ request }) {
  let data = await fetchData(request);
  return json(data);
}

// Export a `Component` directly instead of needing to create a React Element from it
export function Component() {
  let data = useLoaderData();

  return (
    <>
      <h1>You made it!</h1>
      <p>{data}</p>
    </>
  );
}

// Export an `ErrorBoundary` directly instead of needing to create a React Element from it
export function ErrorBoundary() {
  let error = useRouteError();
  return isRouteErrorResponse(error) ? (
    <h1>
      {error.status} {error.statusText}
    </h1>
  ) : (
    <h1>{error.message || error}</h1>
  );
}

An example of this in action can be found in the examples/lazy-loading-router-provider directory of the repository. For more info, check out the lazy docs.

šŸ™Œ Huge thanks to @rossipedia for the Initial Proposal and POC Implementation.

Minor Changes

  • Add support for route.Component/route.ErrorBoundary properties (#10045)
  • Add support for route.lazy (#10045)

Patch Changes

  • Improve memoization for context providers to avoid unnecessary re-renders (#9983)
  • Fix generatePath incorrectly applying parameters in some cases (#10078)
  • [react-router-dom-v5-compat] Add missed data router API re-exports (#10171)

Full Changelog: v6.8.2...v6.9.0

mjackson
published 0.0.0-experimental-633882d6 ā€¢

1
ā€¦
ā€¦
42
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