2026-08-20
每日一文 · 长文精读
React Router v8: A Deliberately Boring Release with ESM-Only Builds and Default Middleware
React Router v8:一次刻意平淡的发布,仅支持 ESM 构建并默认启用中间件
作者:Daniel Curtis · InfoQ 原文
摘要:React Router v8 于 2026 年 6 月 17 日发布,带来了少量破坏性变更、现代化基线(Node 22.22.0+、React 19.2.7+、Vite 7+)以及 ESM 仅构建。中间件默认启用,v6 和 Remix v2 已停止维护。团队强调此次发布“尽可能平淡”,所有破坏性变更均可通过 v7 的未来标志提前采用。迁移指南建议更新依赖并移除已弃用 API。
React Router, the widely used routing library for React that now underpins the Remix framework, has released React Router v8, shipping on June 17, 2026 with a deliberately small set of breaking changes, modernised baselines, and a commitment to a predictable yearly release cadence.
React Router 是广泛使用的 React 路由库,目前支撑着 Remix 框架。它于 2026 年 6 月 17 日发布了 v8 版本,带来了一组刻意精简的破坏性变更、现代化的基线,并承诺采用可预测的年度发布节奏。
React Router v8 introduces updated minimum versions, an ESM-only build, middleware enabled by default, and the graduation of several future flags into standard behaviour.
React Router v8 引入了更新的最低版本要求、仅 ESM 构建、默认启用的中间件,以及将多个未来标志升级为标准行为。
It also marks React Router v6 and Remix v2 as End of Life, so neither will receive further security updates.
它还将 React Router v6 和 Remix v2 标记为生命周期终止,因此两者都不会再收到安全更新。
Writing on the Remix blog, Developer Relations Manager Brooks Lybrand framed the release as intentionally uneventful, explaining that the team's aim for the past several major versions has been to make them "as boring as possible".
在 Remix 博客上,开发者关系经理 Brooks Lybrand 将此次发布描述为刻意平淡,并解释说团队在过去几个主要版本中的目标一直是让它们“尽可能无聊”。
He added that "it's not a major version if nothing broke", while stressing that every breaking change in v8 is one developers could already adopt in v7 through future flags.
他补充说“如果什么都没破坏,那就不算主要版本”,同时强调 v8 中的每个破坏性变更都是开发者可以通过 v7 的未来标志已经采用的。
The new baselines are Node 22.22.0+, React 19.2.7+, and Vite 7+.
新的基线是 Node 22.22.0+、React 19.2.7+ 和 Vite 7+。
To modernise the library, React Router is now published as an ESM-only module, with tsconfig target and lib fields updated to ES2022.
为了现代化库,React Router 现在作为仅 ESM 模块发布,tsconfig 的 target 和 lib 字段已更新为 ES2022。
Four future flags, including v8_middleware and v8_viteEnvironmentApi, have been removed and their behaviours made default, while splitRouteModules moves to a top-level config option that is enabled by default.
四个未来标志(包括 v8_middleware 和 v8_viteEnvironmentApi)已被移除,其行为变为默认,而 splitRouteModules 则移至默认启用的顶级配置选项。
Middleware becoming a baseline drew particular attention.
中间件成为基线引起了特别关注。
In a piece titled "React Router v8 Makes Middleware a Baseline", Roman Fedyskyi wrote that the change pushes frontend teams to "centralize auth, logging, headers", arguing that "many frontend incidents are policy incidents".
在一篇题为“React Router v8 使中间件成为基线”的文章中,Roman Fedyskyi 写道,这一变化促使前端团队“集中管理认证、日志、头部”,并认为“许多前端事故都是策略事故”。
Not all coverage was reassuring, with byteiota warning that "three breaking changes will catch teams off guard" for a package pulling more than 50 million weekly npm downloads.
并非所有报道都令人放心,byteiota 警告说,“三个破坏性变更会让团队措手不及”,而该包每周 npm 下载量超过 5000 万次。
In his React Router v8 and Beyond talk, Lybrand joked that they "broke all your apps, and we did it just to make you mad", a nod to the sceptical reaction on Reddit.
在他的 React Router v8 及未来演讲中,Lybrand 开玩笑说他们“破坏了你们所有的应用,我们这么做就是为了惹恼你们”,这是对 Reddit 上怀疑反应的回应。
Some developers have already looked elsewhere, with The New Stack reporting that some are turning to TanStack Router after the Remix and React Router merger.
一些开发者已经另寻出路,The New Stack 报道称,在 Remix 和 React Router 合并后,一些人正在转向 TanStack Router。
TanStack Router remains the main challenger, promoted for its end-to-end type safety and built-in stale-while-revalidate caching, while Next.js continues to lead on React Server Components maturity.
TanStack Router 仍然是主要挑战者,因其端到端类型安全性和内置的 stale-while-revalidate 缓存而受到推崇,而 Next.js 在 React 服务器组件的成熟度方面继续保持领先。
Migration is designed to be straightforward.
迁移设计得简单直接。
The official upgrade guide advises updating peer dependencies, adopting the future flags, and removing deprecated APIs before installing.
官方升级指南建议在安装前更新对等依赖、采用未来标志并移除已弃用的 API。
A key deprecation is the removal of the react-router-dom package:
一个关键的弃用是移除了 react-router-dom 包:
- import { Link, useLocation } from "react-router-dom";
- import { Link, useLocation } from "react-router-dom";
+ import { Link, useLocation } from "react-router";
+ import { Link, useLocation } from "react-router";
DOM-specific APIs now import from react-router/dom instead.
DOM 特定的 API 现在改为从 react-router/dom 导入。
React Router v8 is already supported on Netlify and by the Sentry SDK, with minor releases up to v8.3.0 following since launch.
React Router v8 已在 Netlify 和 Sentry SDK 上得到支持,自发布以来已跟进到 v8.3.0 的次要版本。
React Router is an open-source library developed via an Open Governance model and maintained by the team at Shopify, with upgrade instructions available at reactrouter.com.
React Router 是一个通过开放治理模型开发的开源库,由 Shopify 团队维护,升级说明可在 reactrouter.com 上获取。
阅读理解
1. What is the main reason the React Router team describes the v8 release as 'as boring as possible'?
2. According to the article, what is a key change regarding the react-router-dom package in React Router v8?
3. Which of the following is NOT mentioned as a new baseline requirement for React Router v8?