Loads of goodies for you this week, as well as a few breaking changes for all of you eager beavers who are brave enough to use beta software in production! đĻĢ
(seriously, thank you all for helping us tighten up our APIs and fix nasty bugs)
đ Breaking Changes!
NavLink
no longer supports theactiveClassName
oractiveStyle
props. Instead, we provide a more powerful API that allows you to pass functions to either theclassName
orstyle
props to conditionally apply values based on the link'sactive
state. While a bit more verbose in some cases, this offers a nicer experience for folks who use utility class-based CSS. (#7194)
// Before
<NavLink className="link" activeClassName="active-link" />
<NavLink style={{ color: "blue" }} activeStyle={{ color: "green" }} />
// After
<NavLink
className={({ isActive }) =>
`link ${
isActive
? "active-link"
: // Couldn't do this before!
"inactive-link"
}`
}
/>
<NavLink style={({ isActive }) => ({ color: isActive ? "green" : "blue" })} />
Note: You can always abstract over this feature in a custom
NavLink
if you prefer the old v5 API.
- The
useRoutes
API has changed slightly. Instead of passing a basename as the second argument, you should instead pass it as a named property in an object:
// Before
useRoutes([...routes], basename);
// After
useRoutes([...routes], { basename });
đ Bugfixes
- The
basename
prop onRoutes
is treated as case-insensitive (#7997) useNavigate
previously used the incorrectpathname
when called from parent routes when the URL matches one of its children. This fix also applies touseSearchParams
(#7880)
⨠Enhancements
Routes
anduseRoutes
now allow you to override thelocation
, which may be useful when building some modal interfaces and route transition animations. We are working hard to update our docs to include examples for advanced patterns where this might be useful, but in the mean time this also bringsRoutes
closer to feature parity with v5'sSwitch
via thelocation
prop. (#7117)- Provided new hooks
useClickHandler
andusePressHandler
to make customizingLinks
a bit easier. (#7998)- Please note: with great power comes great responsibility. If you create a custom
Link
, be sure to render an actual HTML anchor element, otherwise your app will likely be inaccessible without a significant amount of additional work which, I assure you, you don't want to do!
- Please note: with great power comes great responsibility. If you create a custom
đģ Installing
Development for v6 is chugging along on the dev
branch.
If you'd like to test it out, install from npm:
$ npm install history react-router-dom@next
đ Credits
Thanks to @andrelandgraf, @dhulme, @fgatti675, @hugmanrique, @MeiKatz, @chaance and @mjackson for your contributions!