Skip to content

Commit 135e8aa

Browse files
committed
Add note on relative:path starting point
1 parent 9f36087 commit 135e8aa

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/components/link.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ function EditContact() {
9191
}
9292
```
9393

94+
Please note that `relative: "path"` only impacts the resolution of a relative path. It does not change the the "starting" location for that relative path resolution. This resolution is always relative to the current location in the Route hierarchy (i.e., the route `Link` is rendered in).
95+
96+
If you wish to use path-relative routing against the current URL instead of the route hierarchy, you can do that with the current [`location`][use-location] and the `URL` constructor (note the trailing slash behavior):
97+
98+
```js
99+
// Assume the current URL is https://remix.run/docs/en/main/start/quickstart
100+
let location = useLocation();
101+
102+
// Without trailing slashes
103+
new URL(".", window.origin + location.pathname);
104+
// 'https://remix.run/docs/en/main/start/'
105+
new URL("..", window.origin + location.pathname);
106+
// 'https://remix.run/docs/en/main/'
107+
108+
// With trailing slashes:
109+
new URL(".", window.origin + location.pathname + "/");
110+
// 'https://remix.run/docs/en/main/start/future-flags/'
111+
new URL("..", window.origin + location.pathname + "/");
112+
// 'https://remix.run/docs/en/main/start/'
113+
```
114+
94115
## `preventScrollReset`
95116

96117
If you are using [`<ScrollRestoration>`][scrollrestoration], this lets you prevent the scroll position from being reset to the top of the window when the link is clicked.
@@ -205,3 +226,4 @@ function ImageLink(to) {
205226
[picking-a-router]: ../routers/picking-a-router
206227
[navlink]: ./nav-link
207228
[relativesplatpath]: ../hooks/use-resolved-path#splat-paths
229+
[use-location]: ../hooks/use-location

docs/hooks/use-navigate.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ function EditContact() {
9393
}
9494
```
9595

96+
Please note that `relative: "path"` only impacts the resolution of a relative path. It does not change the the "starting" location for that relative path resolution. This resolution is always relative to the current location in the Route hierarchy (i.e., the route `useNavigate` is called in).
97+
98+
If you wish to use path-relative routing against the current URL instead of the route hierarchy, you can do that with the current [`location`][use-location] and the `URL` constructor (note the trailing slash behavior):
99+
100+
```js
101+
// Assume the current URL is https://remix.run/docs/en/main/start/quickstart
102+
let location = useLocation();
103+
104+
// Without trailing slashes
105+
new URL(".", window.origin + location.pathname);
106+
// 'https://remix.run/docs/en/main/start/'
107+
new URL("..", window.origin + location.pathname);
108+
// 'https://remix.run/docs/en/main/'
109+
110+
// With trailing slashes:
111+
new URL(".", window.origin + location.pathname + "/");
112+
// 'https://remix.run/docs/en/main/start/future-flags/'
113+
new URL("..", window.origin + location.pathname + "/");
114+
// 'https://remix.run/docs/en/main/start/'
115+
```
116+
96117
## `options.unstable_flushSync`
97118

98119
The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

0 commit comments

Comments
 (0)