Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

react-router-dom

Package Overview
Dependencies
Maintainers
2
Versions
459
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
ā€¦
ā€¦
46

6.9.0

Diff

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 ā€¢

mjackson
published 0.0.0-experimental-5f6f59a6 ā€¢

mjackson
published 0.0.0-experimental-91f2bf54 ā€¢

mjackson
published 6.9.0-pre.0 ā€¢

mjackson
published 6.8.2 ā€¢

Changelog

Source

v6.8.2

Date: 2023-02-27

Patch Changes

  • Treat same-origin absolute URLs in <Link to> as external if they are outside of the router basename (#10135)
  • Correctly perform a hard redirect for same-origin absolute URLs outside of the router basename (#10076)
  • Fix SSR of absolute <Link to> urls (#10112)
  • Properly escape HTML characters in StaticRouterProvider serialized hydration data (#10068)
  • Fix useBlocker to return IDLE_BLOCKER during SSR (#10046)
  • Ensure status code and headers are maintained for defer loader responses in createStaticHandler's query() method (#10077)
  • Change invariant to an UNSAFE_invariant export since it's only intended for internal use (#10066)

Full Changelog: v6.8.1...v6.8.2

mjackson
published 0.0.0-experimental-e7e9ce6e ā€¢

mjackson
published 0.0.0-experimental-ba938b84 ā€¢

mjackson
published 6.8.2-pre.3 ā€¢

mjackson
published 6.8.2-pre.2 ā€¢

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