diff --git a/.changeset/fetcher-basename.md b/.changeset/fetcher-basename.md new file mode 100644 index 0000000000..5c6ded420c --- /dev/null +++ b/.changeset/fetcher-basename.md @@ -0,0 +1,13 @@ +--- +"react-router-dom": minor +"@remix-run/router": minor +--- + +- Enable relative routing in the `@remix-run/router` when providing a source route ID from which the path is relative to: + + - Example: `router.navigate("../path", { fromRouteId: "some-route" })`. + - This also applies to `router.fetch` which already receives a source route ID + +- Introduce a new `@remix-run/router` `future.v7_prependBasename` flag to enable `basename` prefixing to all paths coming into `router.navigate` and `router.fetch`. + - Previously the `basename` was prepended in the React Router layer, but now that relative routing is being handled by the router we need prepend the `basename` _after_ resolving any relative paths + - This also enables `basename` support in `useFetcher` as well diff --git a/.changeset/stable-navigate-submit.md b/.changeset/stable-navigate-submit.md new file mode 100644 index 0000000000..3ef42d8254 --- /dev/null +++ b/.changeset/stable-navigate-submit.md @@ -0,0 +1,6 @@ +--- +"react-router": patch +"react-router-dom": patch +--- + +When using a `RouterProvider`, `useNavigate`/`useSubmit`/`fetcher.submit` are now stable across location changes, since we can handle relative routing via the `@remix-run/router` instance and get rid of our dependence on `useLocation()`. When using `BrowserRouter`, these hooks remain unstable across location changes because they still rely on `useLocation()`. diff --git a/package.json b/package.json index 1310d4da63..8b95a2d15f 100644 --- a/package.json +++ b/package.json @@ -105,19 +105,19 @@ }, "filesize": { "packages/router/dist/router.umd.min.js": { - "none": "44.2 kB" + "none": "45 kB" }, "packages/react-router/dist/react-router.production.min.js": { - "none": "13.1 kB" + "none": "13.3 kB" }, "packages/react-router/dist/umd/react-router.production.min.js": { - "none": "15.3 kB" + "none": "15.6 kB" }, "packages/react-router-dom/dist/react-router-dom.production.min.js": { - "none": "11.6 kB" + "none": "11.8 kB" }, "packages/react-router-dom/dist/umd/react-router-dom.production.min.js": { - "none": "17.5 kB" + "none": "17.7 kB" } } } diff --git a/packages/react-router-dom-v5-compat/index.ts b/packages/react-router-dom-v5-compat/index.ts index c9c0ee0034..d38c15c840 100644 --- a/packages/react-router-dom-v5-compat/index.ts +++ b/packages/react-router-dom-v5-compat/index.ts @@ -177,6 +177,7 @@ export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_useScrollRestoration, + UNSAFE_useRouteId, } from "./react-router-dom"; export type { StaticRouterProps } from "./lib/components"; diff --git a/packages/react-router-dom/__tests__/data-browser-router-test.tsx b/packages/react-router-dom/__tests__/data-browser-router-test.tsx index b50aee31b7..efc4f23f2e 100644 --- a/packages/react-router-dom/__tests__/data-browser-router-test.tsx +++ b/packages/react-router-dom/__tests__/data-browser-router-test.tsx @@ -33,6 +33,7 @@ import { defer, useLocation, useMatches, + useSearchParams, createRoutesFromElements, } from "react-router-dom"; @@ -2283,6 +2284,69 @@ function testDomRouter( `); }); + it("allows a button to override the